Class: Textus::Handlers::Maintenance::RuleList

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/handlers/maintenance/rule_list.rb

Constant Summary collapse

LIST_FIELDS =
Textus::Manifest::Schema::FIELD_REGISTRY.select { |_, m| m[:in_rule_list] }.keys.freeze

Instance Method Summary collapse

Constructor Details

#initialize(manifest:) ⇒ RuleList

Returns a new instance of RuleList.



5
6
7
# File 'lib/textus/handlers/maintenance/rule_list.rb', line 5

def initialize(manifest:)
  @manifest = manifest
end

Instance Method Details

#call(_command, _call) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/textus/handlers/maintenance/rule_list.rb', line 9

def call(_command, _call)
  Value::Result.success(@manifest.rules.blocks.map do |block|
    row = { "match" => block.match }
    LIST_FIELDS.each do |field|
      value = block.public_send(field)
      row[field.to_s] = serialize(field, value) unless value.nil?
    end
    row
  end)
end

#serialize(field, value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/textus/handlers/maintenance/rule_list.rb', line 22

def serialize(field, value)
  case field
  when :retention then { "ttl_seconds" => value.ttl_seconds, "action" => value.action.to_s }
  when :react then value.to_h
  else value
  end
end