Class: Aid::Auth::Manager
- Inherits:
-
Object
- Object
- Aid::Auth::Manager
- Defined in:
- lib/aid/auth/manager.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #current_account_id ⇒ Object
-
#initialize(context) ⇒ Manager
constructor
A new instance of Manager.
- #strategy ⇒ Object
Constructor Details
#initialize(context) ⇒ Manager
Returns a new instance of Manager.
29 30 31 |
# File 'lib/aid/auth/manager.rb', line 29 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
27 28 29 |
# File 'lib/aid/auth/manager.rb', line 27 def context @context end |
Class Method Details
.enable_strategy(strategy_klass, strategy_config, priority = 0) ⇒ Object
22 23 24 25 |
# File 'lib/aid/auth/manager.rb', line 22 def self.enable_strategy(strategy_klass, strategy_config, priority = 0) self.enabled_strategies ||= [] self.enabled_strategies << EnabledStrategy.new(strategy_klass, strategy_config, priority) end |
Instance Method Details
#authenticated? ⇒ Boolean
40 41 42 |
# File 'lib/aid/auth/manager.rb', line 40 def authenticated? strategy.authenticated? end |
#current_account_id ⇒ Object
44 45 46 |
# File 'lib/aid/auth/manager.rb', line 44 def current_account_id strategy.current_user_id end |
#strategy ⇒ Object
33 34 35 36 37 38 |
# File 'lib/aid/auth/manager.rb', line 33 def strategy strategies = self.class.enabled_strategies.sort{|x, y| y.priority <=> x.priority} es = strategies.select{|s| s.should_use?(@context)}.first es ||= strategies.first (es&.strategy_klass || Strategies::Null).new(es&.strategy_config, @context) end |