thoughtbot / clearance

Rails authentication with email & password.

Home Page:https://thoughtbot.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thoughts on an implementation like the one below to allow for configurable eager loading on the User model?

weilandia opened this issue · comments

Thoughts on an implementation like the one below to allow for configurable eager loading on the User model?

    # The ActiveRecord class that represents users in your application.
    # Defaults to `::User`.
    # @return [ActiveRecord::Base]
    attr_writer :user_model

   # An optional array of records to eager load with current_user
   # Defaults to []
   # @return [Array]
   attr_writer :eager_load

    ...

  # The class representing the configured user model.
  # In the default configuration, this is the `User` class.
  # @return [Class]
  def user_model
    model = (@user_model || "User").to_s.constantize
    model.send(:includes, @eager_load)
  end

default scope is probably clearer