Class: Gruf::Authentication::Strategies
- Inherits:
-
Object
- Object
- Gruf::Authentication::Strategies
- Defined in:
- lib/gruf/authentication/strategies.rb
Overview
Provides a modifiable repository of strategies for authentication
Defined Under Namespace
Classes: StrategyDescendantError
Class Method Summary collapse
-
.[](label) ⇒ Object
Return a strategy via a hash accessor syntax.
-
.add(name, strategy = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block.
- .any? ⇒ Boolean
- .clear ⇒ Hash
-
.each ⇒ Object
Iterate over each.
- .to_h ⇒ Hash<Class>
Class Method Details
.[](label) ⇒ Object
Return a strategy via a hash accessor syntax
49 50 51 |
# File 'lib/gruf/authentication/strategies.rb', line 49 def [](label) _strategies[label.to_sym] end |
.add(name, strategy = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gruf/authentication/strategies.rb', line 33 def add(name, strategy = nil, &block) base = Gruf::Authentication::Base strategy ||= Class.new(base) strategy.class_eval(&block) if block_given? # all strategies require the valid? method raise NoMethodError unless strategy.method_defined?(:valid?) raise StrategyDescendantError, "Strategies must descend from #{base}" unless strategy.ancestors.include?(base) _strategies[name.to_sym] = strategy end |
.any? ⇒ Boolean
72 73 74 |
# File 'lib/gruf/authentication/strategies.rb', line 72 def any? to_h.keys.count > 0 end |
.clear ⇒ Hash
79 80 81 |
# File 'lib/gruf/authentication/strategies.rb', line 79 def clear @strategies = {} end |
.each ⇒ Object
Iterate over each
56 57 58 59 60 |
# File 'lib/gruf/authentication/strategies.rb', line 56 def each _strategies.each do |s| yield s end end |
.to_h ⇒ Hash<Class>
65 66 67 |
# File 'lib/gruf/authentication/strategies.rb', line 65 def to_h _strategies end |