Class: Layer
Overview
Layers Documentation: docs.statsig.com/layers
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#rule_id ⇒ Object
Returns the value of attribute rule_id.
Instance Method Summary collapse
-
#get(index, default_value) ⇒ Object
Get the value for the given key (index), falling back to the default_value if it cannot be found.
-
#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.
-
#initialize(name, value = {}, rule_id = '', exposure_log_func = nil) ⇒ Layer
constructor
A new instance of Layer.
Constructor Details
#initialize(name, value = {}, rule_id = '', exposure_log_func = nil) ⇒ Layer
Returns a new instance of Layer.
21 22 23 24 25 26 |
# File 'lib/layer.rb', line 21 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
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/layer.rb', line 15 def name @name end |
#rule_id ⇒ Object
Returns the value of attribute rule_id.
18 19 20 |
# File 'lib/layer.rb', line 18 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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/layer.rb', line 34 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.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/layer.rb', line 51 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 |