Class: Layer

Inherits:
Object
  • Object
show all
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 = '', group_name = nil, allocated_experiment = nil, exposure_log_func = nil) ⇒ Layer

Returns a new instance of Layer.



16
17
18
19
20
21
22
23
# File 'lib/layer.rb', line 16

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

Instance Attribute Details

#group_nameObject

Returns the value of attribute group_name.



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

def group_name
  @group_name
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/layer.rb', line 10

def name
  @name
end

#rule_idObject

Returns the value of attribute rule_id.



12
13
14
# File 'lib/layer.rb', line 12

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



30
31
32
33
34
35
36
37
38
# File 'lib/layer.rb', line 30

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



46
47
48
49
50
51
52
53
54
55
# File 'lib/layer.rb', line 46

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