Class: Statsig::APIRule

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(name:, pass_percentage:, return_value:, id:, salt:, conditions:, id_type:, group_name: nil, config_delegate: nil, is_experiment_group: nil) ⇒ APIRule

Returns a new instance of APIRule.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api_config.rb', line 54

def initialize(name:, pass_percentage:, return_value:, id:, salt:, conditions:, id_type:,
               group_name: nil, config_delegate: nil, is_experiment_group: nil)
  @name = name
  @pass_percentage = pass_percentage.to_f
  @return_value = JSON.parse(JSON.generate(return_value))
  @id = id
  @salt = salt
  @conditions = conditions
  @id_type = id_type
  @group_name = group_name
  @config_delegate = config_delegate
  @is_experiment_group = is_experiment_group
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



51
52
53
# File 'lib/api_config.rb', line 51

def conditions
  @conditions
end

#config_delegateObject

Returns the value of attribute config_delegate.



51
52
53
# File 'lib/api_config.rb', line 51

def config_delegate
  @config_delegate
end

#group_nameObject

Returns the value of attribute group_name.



51
52
53
# File 'lib/api_config.rb', line 51

def group_name
  @group_name
end

#idObject

Returns the value of attribute id.



51
52
53
# File 'lib/api_config.rb', line 51

def id
  @id
end

#id_typeObject

Returns the value of attribute id_type.



51
52
53
# File 'lib/api_config.rb', line 51

def id_type
  @id_type
end

#is_experiment_groupObject

Returns the value of attribute is_experiment_group.



51
52
53
# File 'lib/api_config.rb', line 51

def is_experiment_group
  @is_experiment_group
end

#nameObject

Returns the value of attribute name.



51
52
53
# File 'lib/api_config.rb', line 51

def name
  @name
end

#pass_percentageObject

Returns the value of attribute pass_percentage.



51
52
53
# File 'lib/api_config.rb', line 51

def pass_percentage
  @pass_percentage
end

#return_valueObject

Returns the value of attribute return_value.



51
52
53
# File 'lib/api_config.rb', line 51

def return_value
  @return_value
end

#saltObject

Returns the value of attribute salt.



51
52
53
# File 'lib/api_config.rb', line 51

def salt
  @salt
end

Class Method Details

.from_json(json) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/api_config.rb', line 68

def self.from_json(json)
  new(
    name: json[:name],
    pass_percentage: json[:passPercentage],
    return_value: json[:returnValue] || {},
    id: json[:id],
    salt: json[:salt],
    conditions: json[:conditions]&.map do |condition|
      APICondition.from_json(condition)
    end,
    id_type: json[:idType],
    group_name: json[:groupName],
    config_delegate: json[:configDelegate],
    is_experiment_group: json[:isExperimentGroup]
  )
end