Class: Unleash::Strategies

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/strategies.rb

Constant Summary collapse

DEFAULT_STRATEGIES =
['applicationHostname', 'default', 'flexibleRollout', 'gradualRolloutRandom', 'gradualRolloutSessionId',
'gradualRolloutUserId', 'remoteAddress', 'userWithId'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStrategies

Returns a new instance of Strategies.



8
9
10
# File 'lib/unleash/strategies.rb', line 8

def initialize
  @strategies = {}
end

Instance Attribute Details

#strategiesObject

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_strategiesObject



22
23
24
# File 'lib/unleash/strategies.rb', line 22

def custom_strategies
  @strategies.values
end

#includes?(name) ⇒ Boolean

Returns:

  • (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_strategiesObject



26
27
28
# File 'lib/unleash/strategies.rb', line 26

def known_strategies
  @strategies.keys.map{ |key| { name: key } }
end