Class: Unleash::Strategies
- Inherits:
-
Object
- Object
- Unleash::Strategies
- Defined in:
- lib/unleash/strategies.rb
Constant Summary collapse
- DEFAULT_STRATEGIES =
['applicationHostname', 'default', 'flexibleRollout', 'gradualRolloutRandom', 'gradualRolloutSessionId', 'gradualRolloutUserId', 'remoteAddress', 'userWithId'].freeze
Instance Attribute Summary collapse
-
#strategies ⇒ Object
Returns the value of attribute strategies.
Instance Method Summary collapse
- #add(strategy) ⇒ Object
- #custom_strategies ⇒ Object
- #includes?(name) ⇒ Boolean
-
#initialize ⇒ Strategies
constructor
A new instance of Strategies.
- #known_strategies ⇒ Object
Constructor Details
#initialize ⇒ Strategies
Returns a new instance of Strategies.
8 9 10 |
# File 'lib/unleash/strategies.rb', line 8 def initialize @strategies = {} end |
Instance Attribute Details
#strategies ⇒ Object
Returns the value of attribute strategies.
6 7 8 |
# File 'lib/unleash/strategies.rb', line 6 def strategies @strategies end |
Instance Method Details
#add(strategy) ⇒ Object
16 17 18 19 20 |
# File 'lib/unleash/strategies.rb', line 16 def add(strategy) raise DefaultOverrideError, "Cannot override a default strategy" if DEFAULT_STRATEGIES.include?(strategy.name) @strategies[strategy.name] = strategy end |
#custom_strategies ⇒ Object
22 23 24 |
# File 'lib/unleash/strategies.rb', line 22 def custom_strategies @strategies.values end |
#includes?(name) ⇒ Boolean
12 13 14 |
# File 'lib/unleash/strategies.rb', line 12 def includes?(name) @strategies.has_key?(name.to_s) || DEFAULT_STRATEGIES.include?(name.to_s) end |
#known_strategies ⇒ Object
26 27 28 |
# File 'lib/unleash/strategies.rb', line 26 def known_strategies @strategies.keys.map{ |key| { name: key } } end |