Class: Unleash::VariantOverride
- Inherits:
-
Object
- Object
- Unleash::VariantOverride
- Defined in:
- lib/unleash/variant_override.rb
Instance Attribute Summary collapse
-
#context_name ⇒ Object
Returns the value of attribute context_name.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(context_name, values = []) ⇒ VariantOverride
constructor
A new instance of VariantOverride.
- #matches_context?(context) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(context_name, values = []) ⇒ VariantOverride
Returns a new instance of VariantOverride.
5 6 7 8 9 10 |
# File 'lib/unleash/variant_override.rb', line 5 def initialize(context_name, values = []) self.context_name = context_name self.values = values || [] validate end |
Instance Attribute Details
#context_name ⇒ Object
Returns the value of attribute context_name.
3 4 5 |
# File 'lib/unleash/variant_override.rb', line 3 def context_name @context_name end |
#values ⇒ Object
Returns the value of attribute values.
3 4 5 |
# File 'lib/unleash/variant_override.rb', line 3 def values @values end |
Instance Method Details
#matches_context?(context) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/unleash/variant_override.rb', line 16 def matches_context?(context) raise ArgumentError, 'context must be of class Unleash::Context' unless context.instance_of?(Unleash::Context) context_value = case self.context_name when 'userId' context.user_id when 'sessionId' context.session_id when 'remoteAddress' context.remote_address else context.properties.fetch(self.context_name, nil) end Unleash.logger.debug "VariantOverride: context_name: #{context_name} context_value: #{context_value}" self.values.include? context_value.to_s end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/unleash/variant_override.rb', line 12 def to_s "<VariantOverride: context_name=#{self.context_name},values=#{self.values}>" end |