Class: Aid::Auth::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/aid/auth/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contextObject

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/aid/auth/manager.rb', line 40

def authenticated?
  strategy.authenticated?
end

#current_account_idObject



44
45
46
# File 'lib/aid/auth/manager.rb', line 44

def 
  strategy.current_user_id
end

#strategyObject



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