Class: Smplkit::Flags::FlagRule

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

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

Class Method 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

#descriptionString? (readonly)

Returns the value of attribute description.

Returns:

  • (String, nil)


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

def description
  @description
end

#logicHash[String, untyped] (readonly)

Returns the value of attribute logic.

Returns:

  • (Hash[String, untyped])


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

def logic
  @logic
end

#valueObject (readonly)

Returns the value of attribute value.

Returns:

  • (Object)


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

def value
  @value
end

Class Method Details

.newFlagRule

Parameters:

  • logic: (Hash[String, untyped])
  • value: (Object)
  • description: (String, nil)

Returns:



13
# File 'sig/smplkit/flags.rbs', line 13

def self.new: (logic: Hash[String, untyped], ?value: untyped, ?description: String?) -> FlagRule

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