Class: Rampart::StrategyManager
- Inherits:
-
Object
- Object
- Rampart::StrategyManager
- Defined in:
- lib/rampart/strategy_manager.rb
Instance Method Summary collapse
- #authenticate!(*names) ⇒ Object
-
#initialize(env) ⇒ StrategyManager
constructor
A new instance of StrategyManager.
- #register(name, strategy) ⇒ Object
Constructor Details
#initialize(env) ⇒ StrategyManager
Returns a new instance of StrategyManager.
6 7 8 9 |
# File 'lib/rampart/strategy_manager.rb', line 6 def initialize(env) @env = env @strategies = {} end |
Instance Method Details
#authenticate!(*names) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rampart/strategy_manager.rb', line 16 def authenticate!(*names) winning_event = FailEvent.new request = Request.new(@env) names.each do |name| strategy = fetch(name) next unless strategy.valid?(request) event = strategy.authenticate!(request) if event.halt? winning_event = event break end end winning_event end |
#register(name, strategy) ⇒ Object
11 12 13 14 |
# File 'lib/rampart/strategy_manager.rb', line 11 def register(name, strategy) raise(ArgumentError, "strategy name already registered: '#{name}'") if @strategies.key?(name) @strategies[name] = strategy end |