Class: Unleash::ActivationStrategy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params, constraints = [], variant_definitions = []) ⇒ ActivationStrategy

Returns a new instance of ActivationStrategy.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unleash/activation_strategy.rb', line 5

def initialize(name, params, constraints = [], variant_definitions = [])
  self.name = name
  self.disabled = false

  if params.is_a?(Hash)
    self.params = params
  elsif params.nil?
    self.params = {}
  else
    Unleash.logger.warn "Invalid params provided for ActivationStrategy (params:#{params})"
    self.params = {}
  end

  if constraints.is_a?(Array) && constraints.all?{ |c| c.is_a?(Constraint) }
    self.constraints = constraints
  else
    Unleash.logger.warn "Invalid constraints provided for ActivationStrategy (constraints: #{constraints})"
    self.disabled = true
    self.constraints = []
  end

  self.variant_definitions = valid_variant_definitions(variant_definitions)
end

Instance Attribute Details

#constraintsObject

Returns the value of attribute constraints.



3
4
5
# File 'lib/unleash/activation_strategy.rb', line 3

def constraints
  @constraints
end

#disabledObject

Returns the value of attribute disabled.



3
4
5
# File 'lib/unleash/activation_strategy.rb', line 3

def disabled
  @disabled
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/unleash/activation_strategy.rb', line 3

def name
  @name
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/unleash/activation_strategy.rb', line 3

def params
  @params
end

#variant_definitionsObject

Returns the value of attribute variant_definitions.



3
4
5
# File 'lib/unleash/activation_strategy.rb', line 3

def variant_definitions
  @variant_definitions
end

Instance Method Details

#matches_context?(context) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/unleash/activation_strategy.rb', line 29

def matches_context?(context)
  self.constraints.any?{ |c| c.matches_context? context }
end