Module: Authentication::Logic::ActsAsAuthentic::Base::Config
- Defined in:
- lib/auth/logic/acts_as_authentic/base.rb
Overview
The primary configuration of a model (often, ‘User`) for use with auth-logic. These methods become class methods of ::ActiveRecord::Base.
Instance Method Summary collapse
-
#acts_as_authentic {|_self| ... } ⇒ Object
This includes a lot of helpful methods for authenticating records which the Authentication::Logic::Session module relies on.
-
#add_acts_as_authentic_module(mod, action = :append) ⇒ Object
Since this part of Authentication::Logic deals with another class, ActiveRecord, we can’t just start including things in ActiveRecord itself.
-
#raise_on_model_setup_error(value = nil) ⇒ Object
(also: #raise_on_model_setup_error=)
Some Authentication::Logic modules requires a database connection with a existing users table by the moment when you call the ‘acts_as_authentic` method.
-
#remove_acts_as_authentic_module(mod) ⇒ Object
This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
Instance Method Details
#acts_as_authentic {|_self| ... } ⇒ Object
This includes a lot of helpful methods for authenticating records which the Authentication::Logic::Session module relies on. To use it just do:
class User < ApplicationRecord
acts_as_authentic
end
Configuration is easy:
acts_as_authentic do |c|
c.my_configuration_option = my_value
end
See the various sub modules for the configuration they provide.
34 35 36 37 38 39 |
# File 'lib/auth/logic/acts_as_authentic/base.rb', line 34 def acts_as_authentic yield self if block_given? return unless db_setup? acts_as_authentic_modules.each { |mod| include mod } end |
#add_acts_as_authentic_module(mod, action = :append) ⇒ Object
Since this part of Authentication::Logic deals with another class, ActiveRecord, we can’t just start including things in ActiveRecord itself. A lot of these module includes need to be triggered by the acts_as_authentic method call. For example, you don’t want to start adding in email validations and what not into a model that has nothing to do with Authentication::Logic.
That being said, this is your tool for extending Authentication::Logic and “hooking” into the acts_as_authentic call.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/auth/logic/acts_as_authentic/base.rb', line 50 def add_acts_as_authentic_module(mod, action = :append) modules = acts_as_authentic_modules.clone case action when :append modules << mod when :prepend modules = [mod] + modules end modules.uniq! self.acts_as_authentic_modules = modules end |
#raise_on_model_setup_error(value = nil) ⇒ Object Also known as: raise_on_model_setup_error=
Some Authentication::Logic modules requires a database connection with a existing users table by the moment when you call the ‘acts_as_authentic` method. If you try to call `acts_as_authentic` without a database connection, it will raise a `Authentication::Logic::ModelSetupError`.
If you rely on the User model before the database is setup correctly, set this field to false.
-
Default:
false -
Accepts:
Boolean
79 80 81 |
# File 'lib/auth/logic/acts_as_authentic/base.rb', line 79 def raise_on_model_setup_error(value = nil) rw_config(:raise_on_model_setup_error, value, false) end |
#remove_acts_as_authentic_module(mod) ⇒ Object
This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
64 65 66 67 68 |
# File 'lib/auth/logic/acts_as_authentic/base.rb', line 64 def remove_acts_as_authentic_module(mod) modules = acts_as_authentic_modules.clone modules.delete(mod) self.acts_as_authentic_modules = modules end |