Class: Layer

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

Overview

Contains the current values from Statsig. Will contain layer default values for all shared parameters in that layer. If a parameter is in an active experiment, and the current user is allocated to that experiment, those parameters will be updated to reflect the experiment values not the layer defaults.

Layers Documentation: docs.statsig.com/layers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = {}, rule_id = '', exposure_log_func = nil) ⇒ Layer

Returns a new instance of Layer.



20
21
22
23
24
25
# File 'lib/layer.rb', line 20

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/layer.rb', line 14

def name
  @name
end

#rule_idObject

Returns the value of attribute rule_id.



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

def rule_id
  @rule_id
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



33
34
35
36
37
38
39
40
41
# File 'lib/layer.rb', line 33

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

  if @exposure_log_func.is_a? Proc
    @exposure_log_func.call(self, index)
  end

  @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



50
51
52
53
54
55
56
57
58
59
# File 'lib/layer.rb', line 50

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

  if @exposure_log_func.is_a? Proc
    @exposure_log_func.call(self, index)
  end

  @value[index]
end