Class: Textus::Protocol::Manifest::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/protocol/manifest/data.rb

Constant Summary collapse

AUDIT_DEFAULTS =
{ max_size: 10_485_760, keep: 1000 }.freeze
WORKER_DEFAULTS =
{ pool: 4, poll: 5, lease_ttl: 60, max_attempts: 3 }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:, root:) ⇒ Data

Returns a new instance of Data.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/textus/protocol/manifest/data.rb', line 37

def initialize(raw:, root:)
  @raw = raw
  @root = root
  @declared_lane_kinds = Textus::Protocol::V4::LANES.keys.to_h { |name| [name, name] }
  @lane_descs = Textus::Protocol::V4::LANES.transform_values { |row| row[:desc] }
  @audit_config = build_audit_config(raw)
  @worker_config = build_worker_config(raw)
  @role_caps = {}
  @entries = build_entries(raw)
  validate_declared_keys!
  freeze
end

Instance Attribute Details

#audit_configObject (readonly)

Returns the value of attribute audit_config.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def audit_config
  @audit_config
end

#declared_lane_kindsObject (readonly)

Returns the value of attribute declared_lane_kinds.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def declared_lane_kinds
  @declared_lane_kinds
end

#entriesObject (readonly)

Returns the value of attribute entries.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def entries
  @entries
end

#lane_descsObject (readonly)

Returns the value of attribute lane_descs.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def lane_descs
  @lane_descs
end

#rawObject (readonly)

Returns the value of attribute raw.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def raw
  @raw
end

#role_capsObject (readonly)

Returns the value of attribute role_caps.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def role_caps
  @role_caps
end

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def root
  @root
end

#worker_configObject (readonly)

Returns the value of attribute worker_config.



10
11
12
# File 'lib/textus/protocol/manifest/data.rb', line 10

def worker_config
  @worker_config
end

Class Method Details

.parse(raw, root:) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/textus/protocol/manifest/data.rb', line 22

def self.parse(raw, root:)
  %w[roles lanes owner].each do |stale_key|
    next unless raw.key?(stale_key)

    raise BadManifest.new(
      "unknown top-level key '#{stale_key}' — protocol textus/4 fixes roles/lanes in " \
      "code; remove this section from manifest.yaml (see CHANGELOG)",
    )
  end
  raise BadManifest.new("manifest must declare data:") if Array(raw["data"]).empty? && raw["data"] != {}

  Schema.validate!(raw)
  new(raw: raw, root: root)
end

.validate_key!(key) ⇒ Object

Raises:



14
15
16
17
18
# File 'lib/textus/protocol/manifest/data.rb', line 14

def self.validate_key!(key)
  raise UsageError.new("empty key") if key.nil? || key.empty?

  Protocol::Key::Grammar.validate!(key)
end

Instance Method Details

#validate_key!(key) ⇒ Object



20
# File 'lib/textus/protocol/manifest/data.rb', line 20

def validate_key!(key) = self.class.validate_key!(key)