Class: Textus::Action::RuleList

Inherits:
Base
  • Object
show all
Defined in:
lib/textus/action/rule_list.rb

Constant Summary collapse

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

Class Method Summary collapse

Methods inherited from Base

inherited, proposal_from

Methods included from Contract::DSL

#arg, #cli, #cli_stdin, #contract, #contract?, #summary, #surfaces, #verb, #view

Class Method Details

.call(container:, call:, **_options) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/textus/action/rule_list.rb', line 12

def self.call(container:, call:, **_options) # rubocop:disable Lint/UnusedMethodArgument
  manifest = container.manifest
  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



26
27
28
29
30
31
32
33
34
35
# File 'lib/textus/action/rule_list.rb', line 26

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