Module: Warden::Strategies

Defined in:
lib/warden/strategies.rb,
lib/warden/strategies/base.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.[](label) ⇒ Object

Provides access to strategies by label :api: public



31
32
33
# File 'lib/warden/strategies.rb', line 31

def [](label)
  _strategies[label]
end

._strategiesObject

:api: private



42
43
44
# File 'lib/warden/strategies.rb', line 42

def _strategies
  @strategies ||= {}
end

.add(label, strategy = nil, &block) ⇒ Object

Add a strategy and store it in a hash.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/warden/strategies.rb', line 6

def add(label, strategy = nil, &block)
  strategy ||= Class.new(Warden::Strategies::Base)
  strategy.class_eval(&block) if block_given?

  unless strategy.method_defined?(:authenticate!)
    raise NoMethodError, "authenticate! is not declared in the #{label.inspect} strategy"
  end

  base = Warden::Strategies::Base
  unless strategy.ancestors.include?(base)
    raise "#{label.inspect} is not a #{base}"
  end

  _strategies[label] = strategy
end

.clear!Object

Clears all declared. :api: public



37
38
39
# File 'lib/warden/strategies.rb', line 37

def clear!
  _strategies.clear
end

.update(label, &block) ⇒ Object

Update a previously given strategy.



23
24
25
26
27
# File 'lib/warden/strategies.rb', line 23

def update(label, &block)
  strategy = _strategies[label]
  raise "Unknown strategy #{label.inspect}" unless strategy
  add(label, strategy, &block)
end