Class: Textus::Manifest::Policy::React

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest/policy/react.rb

Constant Summary collapse

ALLOWED_KEYS =
%w[on when do scope budget idempotency observe priority].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:) ⇒ React

Returns a new instance of React.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/textus/manifest/policy/react.rb', line 9

def initialize(raw:)
  raise Textus::BadManifest.new("react: must be a map") unless raw.is_a?(Hash)

  raw = raw.each_with_object({}) do |(key, value), out|
    normalized = key == true ? "on" : key.to_s
    out[normalized] = value
  end
  raise Textus::BadManifest.new("react.ttl is invalid; ttl belongs only to source.ttl or retention.ttl") if raw.key?("ttl")

  unknown = raw.keys - ALLOWED_KEYS
  raise Textus::BadManifest.new("react: unknown key(s): #{unknown.join(", ")}") unless unknown.empty?

  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/textus/manifest/policy/react.rb', line 7

def raw
  @raw
end

Instance Method Details

#to_hObject



24
25
26
# File 'lib/textus/manifest/policy/react.rb', line 24

def to_h
  @raw
end