Class: DynamicConfig

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dynamic_config.rb

Overview

Contains the current experiment/dynamic config values from Statsig

Dynamic Config Documentation: https://docs.statsig.com/dynamic-config

Experiments Documentation: https://docs.statsig.com/experiments-plus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = {}, rule_id = '') ⇒ DynamicConfig

Returns a new instance of DynamicConfig.



24
25
26
27
28
# File 'lib/dynamic_config.rb', line 24

def initialize(name, value = {}, rule_id = '')
  @name = name
  @value = value
  @rule_id = rule_id
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/dynamic_config.rb', line 15

def name
  @name
end

#rule_idObject

Returns the value of attribute rule_id.



21
22
23
# File 'lib/dynamic_config.rb', line 21

def rule_id
  @rule_id
end

#valueObject

Returns the value of attribute value.



18
19
20
# File 'lib/dynamic_config.rb', line 18

def value
  @value
end

Instance Method Details

#get(index, default_value) ⇒ Object

Get the value for the given key (index), falling back to the default_value if it cannot be found.

Parameters:

  • index

    The name of parameter being fetched

  • default_value

    The fallback value if the name cannot be found



36
37
38
39
# File 'lib/dynamic_config.rb', line 36

def get(index, default_value)
  return default_value if @value.nil? || !@value.key?(index)
  @value[index]
end

#get_typed(index, default_value) ⇒ Object

Get the value for the given key (index), falling back to the default_value if it cannot be found or is found to have a different type from the default_value.

Parameters:

  • index

    The name of parameter being fetched

  • default_value

    The fallback value if the name cannot be found



48
49
50
51
52
# File 'lib/dynamic_config.rb', line 48

def get_typed(index, default_value)
  return default_value if @value.nil? || !@value.key?(index)
  return default_value if @value[index].class != default_value.class and default_value.class != TrueClass and default_value.class != FalseClass
  @value[index]
end