Class: Flagsmith::Engine::Segment

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

Overview

SegmentModel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, rules: [], feature_states: []) ⇒ Segment

Returns a new instance of Segment.



12
13
14
15
16
17
# File 'lib/flagsmith/engine/segments/models.rb', line 12

def initialize(id:, name:, rules: [], feature_states: [])
  @id = id
  @name = name
  @rules = rules
  @feature_states = feature_states
end

Instance Attribute Details

#feature_statesObject

Returns the value of attribute feature_states.



10
11
12
# File 'lib/flagsmith/engine/segments/models.rb', line 10

def feature_states
  @feature_states
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/flagsmith/engine/segments/models.rb', line 9

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/flagsmith/engine/segments/models.rb', line 9

def name
  @name
end

#rulesObject

Returns the value of attribute rules.



10
11
12
# File 'lib/flagsmith/engine/segments/models.rb', line 10

def rules
  @rules
end

Class Method Details

.build(json) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/flagsmith/engine/segments/models.rb', line 20

def build(json)
  feature_states = json.fetch(:feature_states, []).map { |fs| Flagsmith::Engine::FeatureState.build(fs) }
  rules = json.fetch(:rules, []).map { |rule| Flagsmith::Engine::Segments::Rule.build(rule) }

  new(
    **json.slice(:id, :name)
          .merge(feature_states: feature_states, rules: rules)
  )
end