Class: Auth::Model
Defined Under Namespace
Modules: Authenticated
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_options! ⇒ Object
-
#initialize(name_or_constant, options = {}) ⇒ Model
constructor
Options include: :behaviors => an array of behaviors to override Auth.configuration.behaviors :password_update_frequency => a time (ie 30.days) to override Auth.configuration.password_update_frequency :skip_routes => true if you do not want to generate routes (useful if you need to map them yourself).
-
#key ⇒ Object
The key upon which this model is to be authenticated.
-
#matches?(name_or_constant) ⇒ Boolean
Returns true if the specified String, Symbol or constant resolves to the same constant affected by this Model.
-
#merge_options!(options) ⇒ Object
Merges the specified hash of options with this Model’s hash of options.
- #target ⇒ Object
Methods included from BehaviorLookup
Constructor Details
#initialize(name_or_constant, options = {}) ⇒ Model
Options include:
:behaviors => an array of behaviors to override Auth.configuration.behaviors
:password_update_frequency => a time (ie 30.days) to override Auth.configuration.password_update_frequency
:skip_routes => true if you do not want to generate routes (useful if you need to map them yourself).
:key => the key upon which to authenticate (the username, basically)
:with => a regular expression used to validate the password
:accounts_controller => the name of the controller to route to for creating accounts, deleting them, etc.
:sessions_controller => the name of the controller to route to for logging in, logging out, etc.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/auth/model.rb', line 32 def initialize(name_or_constant, = {}) begin @target = resolve(name_or_constant).name rescue NameError # we fail silently because the user might not have generated the model yet. That would mean they're trying # to do it now. @target = name_or_constant.to_s.camelize end @options = .reverse_merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/auth/model.rb', line 16 def @options end |
Class Method Details
.option(name, default = name) ⇒ Object
9 10 11 12 13 |
# File 'lib/auth/model.rb', line 9 def self.option(name, default = name) define_method(name) do self.[name] ||= Auth.configuration.send(default) end end |
Instance Method Details
#apply_options! ⇒ Object
68 69 70 |
# File 'lib/auth/model.rb', line 68 def apply_behaviors! end |
#key ⇒ Object
The key upon which this model is to be authenticated. (The username.) Defaults to :email
59 60 61 |
# File 'lib/auth/model.rb', line 59 def key [:key] end |
#matches?(name_or_constant) ⇒ Boolean
Returns true if the specified String, Symbol or constant resolves to the same constant affected by this Model.
54 55 56 |
# File 'lib/auth/model.rb', line 54 def matches?(name_or_constant) target == resolve(name_or_constant) end |
#merge_options!(options) ⇒ Object
Merges the specified hash of options with this Model’s hash of options. Same as model.options.merge!(options)
64 65 66 |
# File 'lib/auth/model.rb', line 64 def () self..merge! end |
#target ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/auth/model.rb', line 44 def target returning @target.constantize do |klass| unless klass.include?(Auth::Model::Authenticated) klass.send(:include, Auth::Model::Authenticated) klass.sparkly_config = self end end end |