Class: Warden::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/warden/config.rb

Overview

This class is yielded inside Warden::Manager. If you have a plugin and want to add more configuration to warden, you just need to extend this class.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(other = {}) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
42
43
# File 'lib/warden/config.rb', line 37

def initialize(other={})
  merge!(other)
  self[:default_scope]      ||= :default
  self[:scope_defaults]     ||= {}
  self[:default_strategies] ||= {}
  self[:intercept_401] = true unless key?(:intercept_401)
end

Class Method Details

.hash_accessor(*names) ⇒ Object

Creates an accessor that simply sets and reads a key in the hash:

class Config < Hash
  hash_accessor :failure_app
end

config = Config.new
config.failure_app = Foo
config[:failure_app] #=> Foo

config[:failure_app] = Bar
config.failure_app #=> Bar


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_strategies(*strategies) ⇒ Object

Set the default strategies to use. :api: public



63
64
65
66
67
68
69
70
# File 'lib/warden/config.rb', line 63

def default_strategies(*strategies)
  opts  = Hash === strategies.last ? strategies.pop : {}
  hash  = self[:default_strategies]
  scope = opts[:scope] || :_all

  hash[scope] = strategies.flatten unless strategies.empty?
  hash[scope] || hash[:_all] || []
end

#initialize_copy(other) ⇒ Object



45
46
47
48
49
# File 'lib/warden/config.rb', line 45

def initialize_copy(other)
  super
  deep_dup(:scope_defaults, other)
  deep_dup(:default_strategies, other)
end

#scope_defaults(scope, opts = {}) ⇒ Object

A short hand way to set up a particular scope :api: public



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/warden/config.rb', line 74

def scope_defaults(scope, opts = {})
  if strategies = opts.delete(:strategies)
    default_strategies(strategies, :scope => scope)
  end

  if opts.empty?
    self[:scope_defaults][scope] || {}
  else
    self[:scope_defaults][scope] ||= {}
    self[:scope_defaults][scope].merge!(opts)
  end
end

#serialize_from_session(*args, &block) ⇒ Object

Hook from configuration to serialize_from_session. :api: public



101
102
103
# File 'lib/warden/config.rb', line 101

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



95
96
97
# File 'lib/warden/config.rb', line 95

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. :api: plugin



53
54
55
# File 'lib/warden/config.rb', line 53

def silence_missing_strategies!
  self[:silence_missing_strategies] = true
end

#silence_missing_strategies?Boolean

:nodoc:

Returns:

  • (Boolean)


57
58
59
# File 'lib/warden/config.rb', line 57

def silence_missing_strategies? #:nodoc:
  !!self[:silence_missing_strategies]
end

#strategiesObject

Quick accessor to strategies from manager :api: public



89
90
91
# File 'lib/warden/config.rb', line 89

def strategies
  Warden::Strategies
end