Class: ActiveSecurity::Configuration
- Inherits:
-
Object
- Object
- ActiveSecurity::Configuration
- Defined in:
- lib/active_security/configuration.rb
Overview
The configuration parameters passed to Base#active_security will be stored in this object.
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
The default configuration options.
-
#finder_methods ⇒ Object
The module to use for finders.
-
#logger ⇒ Object
Where logs will be sent.
-
#model_class ⇒ Object
The model class that this configuration belongs to.
-
#modules ⇒ Object
readonly
The modules in use.
Instance Method Summary collapse
- #_handle_hash(hash) ⇒ Object
- #_use(mod, idx) {|_self| ... } ⇒ Object
-
#initialize(model_class, values = nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#use(*modules, &block) ⇒ Object
Lets you specify the addon modules to use with ActiveSecurity.
-
#uses?(mod) ⇒ Boolean
Returns whether the given module is in use.
Constructor Details
#initialize(model_class, values = nil) ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 27 28 |
# File 'lib/active_security/configuration.rb', line 21 def initialize(model_class, values = nil) @model_class = model_class @defaults = {} @logger = ActiveRecord::Base.logger @modules = [] @finder_methods = ActiveSecurity::FinderMethods set(values) end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
The default configuration options.
6 7 8 |
# File 'lib/active_security/configuration.rb', line 6 def defaults @defaults end |
#finder_methods ⇒ Object
The module to use for finders
16 17 18 |
# File 'lib/active_security/configuration.rb', line 16 def finder_methods @finder_methods end |
#logger ⇒ Object
Where logs will be sent
19 20 21 |
# File 'lib/active_security/configuration.rb', line 19 def logger @logger end |
#model_class ⇒ Object
The model class that this configuration belongs to.
13 14 15 |
# File 'lib/active_security/configuration.rb', line 13 def model_class @model_class end |
#modules ⇒ Object (readonly)
The modules in use
9 10 11 |
# File 'lib/active_security/configuration.rb', line 9 def modules @modules end |
Instance Method Details
#_handle_hash(hash) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/active_security/configuration.rb', line 72 def _handle_hash(hash) hash.each do |mod_key, attrs| mod = get_module(mod_key) _use(mod, 0) do |config| config.send(:set, attrs) end end end |
#_use(mod, idx) {|_self| ... } ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/active_security/configuration.rb', line 81 def _use(mod, idx, &block) mod.setup(@model_class) if mod.respond_to?(:setup) @model_class.send(:include, mod) unless uses?(mod) # Only yield on the first module, so as to not run the block multiple times, # and because later modules may require the attributes of a prior module to exist. # The block structure won't work for more complex config than that. # For more complex configuration pass a Hash where the keys are the "modules" yield self if block_given? && idx.zero? mod.after_config(@model_class) if mod.respond_to?(:after_config) end |
#use(*modules, &block) ⇒ Object
Lets you specify the addon modules to use with ActiveSecurity.
This method is invoked by active_security when passing the ‘:use` option, or when using active_security with a block.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/active_security/configuration.rb', line 48 def use(*modules, &block) mods = modules.to_a.compact mods.map.with_index do |object, idx| case object when Array object.each do |obj| if obj.is_a?(Hash) _handle_hash(obj) else mod = get_module(obj) _use(mod, idx, &block) end end when Hash _handle_hash(object) when String, Symbol, Module mod = get_module(object) _use(mod, idx, &block) else raise InvalidConfig, "Unknown Argument Type #{object.class}: #{object.inspect}" end end end |
#uses?(mod) ⇒ Boolean
Returns whether the given module is in use.
93 94 95 |
# File 'lib/active_security/configuration.rb', line 93 def uses?(mod) @model_class < get_module(mod) end |