Class: Unleash::VariantDefinition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, weight = 0, payload = nil, stickiness = nil, overrides = []) ⇒ VariantDefinition

rubocop:disable Metrics/ParameterLists



7
8
9
10
11
12
13
14
15
# File 'lib/unleash/variant_definition.rb', line 7

def initialize(name, weight = 0, payload = nil, stickiness = nil, overrides = []) # rubocop:disable Metrics/ParameterLists
  self.name = name
  self.weight = weight
  self.payload = payload
  self.stickiness = stickiness
  self.overrides = (overrides || [])
    .select{ |v| v.is_a?(Hash) && v.has_key?('contextName') }
    .map{ |v| VariantOverride.new(v.fetch('contextName', ''), v.fetch('values', [])) } || []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/unleash/variant_definition.rb', line 5

def name
  @name
end

#overridesObject

Returns the value of attribute overrides.



5
6
7
# File 'lib/unleash/variant_definition.rb', line 5

def overrides
  @overrides
end

#payloadObject

Returns the value of attribute payload.



5
6
7
# File 'lib/unleash/variant_definition.rb', line 5

def payload
  @payload
end

#stickinessObject

Returns the value of attribute stickiness.



5
6
7
# File 'lib/unleash/variant_definition.rb', line 5

def stickiness
  @stickiness
end

#weightObject

Returns the value of attribute weight.



5
6
7
# File 'lib/unleash/variant_definition.rb', line 5

def weight
  @weight
end

Instance Method Details

#override_matches_context?(context) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/unleash/variant_definition.rb', line 17

def override_matches_context?(context)
  self.overrides.select{ |o| o.matches_context?(context) }.first
end

#to_sObject



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

def to_s
  "<VariantDefinition: name=#{self.name},weight=#{self.weight},payload=#{self.payload},stickiness=#{self.stickiness}" \
      ",overrides=#{self.overrides}>"
end