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 = []) ⇒ 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
# File 'lib/unleash/activation_strategy.rb', line 5

def initialize(name, params, constraints = [])
  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.each{ |c| c.is_a?(Constraint) }
    self.constraints = constraints
  else
    Unleash.logger.warn "Invalid constraints provided for ActivationStrategy (contraints: #{constraints})"
    self.disabled = true
    self.constraints = []
  end
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

Instance Method Details

#matches_context?(context) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/unleash/activation_strategy.rb', line 27

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