Class: Unleash::Variant

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Variant

Returns a new instance of Variant.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
# File 'lib/unleash/variant.rb', line 5

def initialize(params = {})
  raise ArgumentError, "Variant initializer requires a hash." unless params.is_a?(Hash)

  self.name = params.values_at('name', :name).compact.first
  self.enabled = params.values_at('enabled', :enabled).compact.first || false
  self.payload = params.values_at('payload', :payload).compact.first
  self.feature_enabled = params.values_at('feature_enabled', :feature_enabled).compact.first || false

  raise ArgumentError, "Variant requires a name." if self.name.nil?
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#feature_enabledObject

Returns the value of attribute feature_enabled.



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

def feature_enabled
  @feature_enabled
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#payloadObject

Returns the value of attribute payload.



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

def payload
  @payload
end

Class Method Details

.disabled_variantObject



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

def self.disabled_variant
  Variant.new(name: 'disabled', enabled: false, feature_enabled: false)
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  self.name == other.name && self.enabled == other.enabled && self.payload == other.payload \
    && self.feature_enabled == other.feature_enabled
end

#to_sObject



16
17
18
19
20
# File 'lib/unleash/variant.rb', line 16

def to_s
  # :nocov:
  "<Variant: name=#{self.name},enabled=#{self.enabled},payload=#{self.payload},feature_enabled=#{self.feature_enabled}>"
  # :nocov:
end