Class: Flagsmith::Engine::Segments::Rule

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/flagsmith/engine/segments/models.rb

Overview

SegmentRuleModel

Constant Summary collapse

MATCHING_FUNCTIONS =
{
  ANY_RULE => :any?,
  ALL_RULE => :all?,
  NONE_RULE => :none?
}.freeze

Constants included from Constants

Constants::ALL_RULE, Constants::ANY_RULE, Constants::CONDITION_OPERATORS, Constants::CONTAINS, Constants::EQUAL, Constants::GREATER_THAN, Constants::GREATER_THAN_INCLUSIVE, Constants::IN, Constants::IS_NOT_SET, Constants::IS_SET, Constants::LESS_THAN, Constants::LESS_THAN_INCLUSIVE, Constants::MODULO, Constants::NONE_RULE, Constants::NOT_CONTAINS, Constants::NOT_EQUAL, Constants::PERCENTAGE_SPLIT, Constants::REGEX, Constants::RULE_TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, rules: [], conditions: []) ⇒ Rule

Returns a new instance of Rule.



114
115
116
117
118
# File 'lib/flagsmith/engine/segments/models.rb', line 114

def initialize(type: nil, rules: [], conditions: [])
  @type = type
  @rules = rules
  @conditions = conditions
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



112
113
114
# File 'lib/flagsmith/engine/segments/models.rb', line 112

def conditions
  @conditions
end

#rulesObject

Returns the value of attribute rules.



112
113
114
# File 'lib/flagsmith/engine/segments/models.rb', line 112

def rules
  @rules
end

#typeObject

Returns the value of attribute type.



112
113
114
# File 'lib/flagsmith/engine/segments/models.rb', line 112

def type
  @type
end

Class Method Details

.build(json) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/flagsmith/engine/segments/models.rb', line 125

def build(json)
  rules = json.fetch(:rules, []).map { |r| Flagsmith::Engine::Segments::Rule.build(r) }
  conditions = json.fetch(:conditions, []).map { |c| Flagsmith::Engine::Segments::Condition.build(c) }
  new(
    type: json[:type], rules: rules, conditions: conditions
  )
end

Instance Method Details

#matching_functionObject



120
121
122
# File 'lib/flagsmith/engine/segments/models.rb', line 120

def matching_function
  MATCHING_FUNCTIONS[type]
end