Class: Smplkit::Flags::FlagRule

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/flags/models.rb

Overview

A single targeting rule on a Flag.

Lives in FlagEnvironment#rules. Frozen — author rules via the Smplkit::Rule fluent builder and pass through Flag#add_rule.

Attributes:

- logic: JSON Logic predicate. Empty Hash means "always match".
- value: Value to serve when +logic+ evaluates truthy.
- description: Human-readable label (optional).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logic:, value: nil, description: nil) ⇒ FlagRule

Returns a new instance of FlagRule.



23
24
25
26
27
28
# File 'lib/smplkit/flags/models.rb', line 23

def initialize(logic:, value: nil, description: nil)
  @logic = logic
  @value = value
  @description = description
  freeze
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



21
22
23
# File 'lib/smplkit/flags/models.rb', line 21

def description
  @description
end

#logicObject (readonly)

Returns the value of attribute logic.



21
22
23
# File 'lib/smplkit/flags/models.rb', line 21

def logic
  @logic
end

#valueObject (readonly)

Returns the value of attribute value.



21
22
23
# File 'lib/smplkit/flags/models.rb', line 21

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



30
31
32
# File 'lib/smplkit/flags/models.rb', line 30

def ==(other)
  other.is_a?(FlagRule) && logic == other.logic && value == other.value && description == other.description
end

#hashObject



35
# File 'lib/smplkit/flags/models.rb', line 35

def hash = [logic, value, description].hash