Class: Warden::Config
- Inherits:
-
Hash
- Object
- Hash
- Warden::Config
- Defined in:
- lib/warden/config.rb
Overview
This is a class which is yielded on use Warden::Manager. If you have a plugin and wants to add more configuration to warden, you just need to extend this class.
Class Method Summary collapse
-
.hash_accessor(*names) ⇒ Object
Creates an accessor that simply sets and reads a key in the hash:.
Instance Method Summary collapse
-
#default_scope_options(scope = default_scope, opts = nil) ⇒ Object
Set the default options that are passed to set_user.
-
#default_strategies(*strategies) ⇒ Object
Set the default strategies to use.
-
#initialize(other = {}) ⇒ Config
constructor
A new instance of Config.
-
#scope_defaults(scope, opts = {}) ⇒ Object
A short hand way to set up a particular scope.
-
#serialize_from_session(*args, &block) ⇒ Object
Hook from configuration to serialize_from_session.
-
#serialize_into_session(*args, &block) ⇒ Object
Hook from configuration to serialize_into_session.
-
#silence_missing_strategies! ⇒ Object
Do not raise an error if a missing strategy is given by default.
-
#silence_missing_strategies? ⇒ Boolean
:nodoc:.
-
#strategies ⇒ Object
Quick accessor to strategies from manager :api: public.
Constructor Details
#initialize(other = {}) ⇒ Config
Returns a new instance of Config.
37 38 39 40 41 42 |
# File 'lib/warden/config.rb', line 37 def initialize(other={}) merge!(other) self[:default_scope] ||= :default self[:default_scope_options] ||= {} self[:default_strategies] ||= {} end |
Class Method Details
.hash_accessor(*names) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/warden/config.rb', line 21 def self.hash_accessor(*names) #:nodoc: names.each do |name| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} self[:#{name}] end def #{name}=(value) self[:#{name}] = value end METHOD end end |
Instance Method Details
#default_scope_options(scope = default_scope, opts = nil) ⇒ Object
Set the default options that are passed to set_user. This is configured during the setup phase and is used throughout.
68 69 70 71 72 73 74 75 76 |
# File 'lib/warden/config.rb', line 68 def (scope = default_scope, opts = nil) if opts.nil? # We're reading the default options for this scope self[:default_scope_options][scope] ||= {} else # We're setting the default options forthe scope self[:default_scope_options][scope] = opts end end |
#default_strategies(*strategies) ⇒ Object
Set the default strategies to use. :api: public
56 57 58 59 60 61 62 63 64 |
# File 'lib/warden/config.rb', line 56 def default_strategies(*strategies) opts = Hash === strategies.last ? strategies.pop : {} scope = opts[:scope] || default_scope if strategies.empty? self[:default_strategies][scope] else self[:default_strategies][scope] = strategies.flatten end end |
#scope_defaults(scope, opts = {}) ⇒ Object
A short hand way to set up a particular scope
79 80 81 82 83 84 |
# File 'lib/warden/config.rb', line 79 def scope_defaults(scope, opts = {}) strategies = opts.delete(:strategies) || [] default_strategies(strategies, :scope => scope) (scope, opts) true end |
#serialize_from_session(*args, &block) ⇒ Object
Hook from configuration to serialize_from_session. :api: public
100 101 102 |
# File 'lib/warden/config.rb', line 100 def serialize_from_session(*args, &block) Warden::Manager.serialize_from_session(*args, &block) end |
#serialize_into_session(*args, &block) ⇒ Object
Hook from configuration to serialize_into_session. :api: public
94 95 96 |
# File 'lib/warden/config.rb', line 94 def serialize_into_session(*args, &block) Warden::Manager.serialize_into_session(*args, &block) end |
#silence_missing_strategies! ⇒ Object
Do not raise an error if a missing strategy is given by default. :api: plugin
46 47 48 |
# File 'lib/warden/config.rb', line 46 def silence_missing_strategies! self[:silence_missing_strategies] = true end |
#silence_missing_strategies? ⇒ Boolean
:nodoc:
50 51 52 |
# File 'lib/warden/config.rb', line 50 def silence_missing_strategies? #:nodoc: !!self[:silence_missing_strategies] end |
#strategies ⇒ Object
Quick accessor to strategies from manager :api: public
88 89 90 |
# File 'lib/warden/config.rb', line 88 def strategies Warden::Strategies end |