Class: Statsig::APICondition

Inherits:
Object
  • Object
show all
Defined in:
lib/api_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, target_value:, operator:, field:, additional_values:, id_type:) ⇒ APICondition

Returns a new instance of APICondition.



92
93
94
95
96
97
98
99
# File 'lib/api_config.rb', line 92

def initialize(type:, target_value:, operator:, field:, additional_values:, id_type:)
  @type = type.to_sym unless type.nil?
  @target_value = target_value
  @operator = operator.to_sym unless operator.nil?
  @field = field
  @additional_values = additional_values || {}
  @id_type = id_type
end

Instance Attribute Details

#additional_valuesObject

Returns the value of attribute additional_values.



90
91
92
# File 'lib/api_config.rb', line 90

def additional_values
  @additional_values
end

#fieldObject

Returns the value of attribute field.



90
91
92
# File 'lib/api_config.rb', line 90

def field
  @field
end

#id_typeObject

Returns the value of attribute id_type.



90
91
92
# File 'lib/api_config.rb', line 90

def id_type
  @id_type
end

#operatorObject

Returns the value of attribute operator.



90
91
92
# File 'lib/api_config.rb', line 90

def operator
  @operator
end

#target_valueObject

Returns the value of attribute target_value.



90
91
92
# File 'lib/api_config.rb', line 90

def target_value
  @target_value
end

#typeObject

Returns the value of attribute type.



90
91
92
# File 'lib/api_config.rb', line 90

def type
  @type
end

Class Method Details

.from_json(json) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/api_config.rb', line 101

def self.from_json(json)
  operator = json[:operator]
  unless operator.nil?
    operator = operator&.downcase&.to_sym
    unless Const::SUPPORTED_OPERATORS.include?(operator)
      raise UnsupportedConfigException
    end
  end

  type = json[:type]
  unless type.nil?
    type = type&.downcase&.to_sym
    unless Const::SUPPORTED_CONDITION_TYPES.include?(type)
      raise UnsupportedConfigException
    end
  end

  new(
    type: json[:type],
    target_value: json[:targetValue],
    operator: json[:operator],
    field: json[:field],
    additional_values: json[:additionalValues],
    id_type: json[:idType]
  )
end