Class: Otto::Security::Authentication::RouteAuthWrapperComponents::StrategyResolver
- Inherits:
-
Object
- Object
- Otto::Security::Authentication::RouteAuthWrapperComponents::StrategyResolver
- Defined in:
- lib/otto/security/authentication/route_auth_wrapper/strategy_resolver.rb
Overview
Resolves authentication strategy names to strategy instances
Handles strategy lookup with caching and pattern matching:
-
Exact match: ‘authenticated’ → looks up auth_config[‘authenticated’]
-
Prefix match: ‘custom:value’ → looks up ‘custom’ strategy
Results are cached to avoid repeated lookups for the same requirement.
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Clear the strategy cache.
-
#initialize(auth_config) ⇒ StrategyResolver
constructor
A new instance of StrategyResolver.
-
#resolve(requirement) ⇒ Array<AuthStrategy, String>, Array<nil, nil>
Resolve a requirement string to a strategy instance.
Constructor Details
#initialize(auth_config) ⇒ StrategyResolver
Returns a new instance of StrategyResolver.
22 23 24 25 |
# File 'lib/otto/security/authentication/route_auth_wrapper/strategy_resolver.rb', line 22 def initialize(auth_config) @auth_config = auth_config @cache = {} end |
Instance Method Details
#clear_cache ⇒ Object
Clear the strategy cache
43 44 45 |
# File 'lib/otto/security/authentication/route_auth_wrapper/strategy_resolver.rb', line 43 def clear_cache @cache.clear end |
#resolve(requirement) ⇒ Array<AuthStrategy, String>, Array<nil, nil>
Resolve a requirement string to a strategy instance
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/otto/security/authentication/route_auth_wrapper/strategy_resolver.rb', line 31 def resolve(requirement) return [nil, nil] unless @auth_config && @auth_config[:auth_strategies] # Check cache first return @cache[requirement] if @cache.key?(requirement) result = find_strategy(requirement) @cache[requirement] = result result end |