Module: Authlogic::AuthenticatesMany::Base
- Defined in:
- lib/authlogic/authenticates_many/base.rb
Overview
These methods become class methods of ::ActiveRecord::Base.
Constant Summary collapse
- DPR_AUTH_MANY =
<<~EOS.freeze authenticates_many is deprecated without replacement. Let us know if you would like to take over maintenance of this feature as a separate gem. If no one volunteers to extract and maintain a new gem, then this feature will simply be deleted. EOS
Instance Method Summary collapse
-
#authenticates_many(name, options = {}) ⇒ Object
Allows you to set up a relationship with your sessions.
Instance Method Details
#authenticates_many(name, options = {}) ⇒ Object
Allows you to set up a relationship with your sessions. See module definition above for more details.
Options
-
session_class:
default: “#nameSession”, This is the related session class. -
relationship_name:
default: options.klass_name.underscore.pluralize, This is the name of the relationship you want to use to scope everything. For example an Account has many Users. There should be a relationship called :users that you defined with a has_many. The reason we use the relationship is so you don’t have to repeat yourself. The relationship could have all kinds of custom options. So instead of repeating yourself we essentially use the scope that the relationship creates. -
find_options:
default: nil, By default the find options are created from the relationship you specify with :relationship_name. But if you want to override this and manually specify find_options you can do it here. Specify options just as you would in ActiveRecord::Base.find. -
scope_cookies:
default: false By the nature of cookies they scope themselves if you are using subdomains to access accounts. If you aren’t using subdomains you need to have separate cookies for each account, assuming a user is logging into more than one account. Authlogic can take care of this for you by prefixing the name of the cookie and session with the model id. Because it affects both cookies names and session keys, the name ‘scope_cookies` is misleading. Perhaps simply `scope` or `scoped` would have been better.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/authlogic/authenticates_many/base.rb', line 62 def authenticates_many(name, = {}) ::ActiveSupport::Deprecation.warn(DPR_AUTH_MANY) [:session_class] ||= name.to_s.classify.constantize [:relationship_name] ||= [:session_class].klass_name.underscore.pluralize class_eval <<-EOS, __FILE__, __LINE__ + 1 def #{name} find_options = #{[:].inspect} || #{[:relationship_name]}.where(nil) @#{name} ||= Authlogic::AuthenticatesMany::Association.new( #{[:session_class]}, find_options, #{[:] ? "self.class.model_name.name.underscore + '_' + self.send(self.class.primary_key).to_s" : 'nil'} ) end EOS end |