Class: Textus::Manifest::Data

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

Overview

Immutable, parsed view of a manifest YAML document.

Holds raw structural data (zones, entries, audit_config, role_caps) but no behaviour beyond accessors. Behaviour (zone authority, key resolution, rules) lives on Manifest::Policy / Resolver / Rules.

Constant Summary collapse

AUDIT_DEFAULTS =
{ max_size: 10_485_760, keep: 5 }.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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/textus/manifest/data.rb', line 35

def initialize(raw:, root:)
  @raw = raw
  @root = root
  # Write authority is derived from capabilities × zone-kind (ADR 0030),
  # not a per-zone writer list. "Which zones are declared" lives in the
  # one kind-keyed map below (declared_zone_kinds); membership checks by
  # read-side callers (boot, maintenance/zone_mv) use its keyset (ADR 0034).
  @declared_zone_kinds = Array(raw["zones"]).to_h do |z|
    [z["name"], z["kind"]&.to_sym]
  end
  @zone_descs  = Array(raw["zones"]).to_h { |z| [z["name"], z["desc"]] }
  # Only zones that actually declare an owner — keep nil-tombstones out so a
  # future `zone_owners.key?(name)` means "owner declared", not "zone exists".
  @zone_owners = Array(raw["zones"]).to_h { |z| [z["name"], z["owner"]] }.compact
  @audit_config = build_audit_config(raw)
  @role_caps = Capabilities.resolve(raw["roles"])
  # Policy is constructed before entries because Entry validators
  # call `entry.in_generator_zone?(policy)` and similar helpers
  # that take Policy as an argument.
  @policy = Policy.new(self)
  @entries = build_entries(raw)
  validate_declared_keys!
  freeze
end

Instance Attribute Details

#audit_configObject (readonly)

Returns the value of attribute audit_config.



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

def audit_config
  @audit_config
end

#declared_zone_kindsObject (readonly)

Returns the value of attribute declared_zone_kinds.



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

def declared_zone_kinds
  @declared_zone_kinds
end

#entriesObject (readonly)

Returns the value of attribute entries.



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

def entries
  @entries
end

#policyObject (readonly)

Returns the value of attribute policy.



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

def policy
  @policy
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#role_capsObject (readonly)

Returns the value of attribute role_caps.



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

def role_caps
  @role_caps
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

#zone_descsObject (readonly)

Returns the value of attribute zone_descs.



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

def zone_descs
  @zone_descs
end

#zone_ownersObject (readonly)

Returns the value of attribute zone_owners.



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

def zone_owners
  @zone_owners
end

Class Method Details

.parse(raw, root:) ⇒ Object

Raises:



28
29
30
31
32
33
# File 'lib/textus/manifest/data.rb', line 28

def self.parse(raw, root:)
  raise BadFrontmatter.new(File.join(root.to_s, "manifest.yaml"), "manifest must declare zones:") if Array(raw["zones"]).empty?

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

.validate_key!(key) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/textus/manifest/data.rb', line 18

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

  Key::Grammar.validate!(key)
end

Instance Method Details

#validate_key!(key) ⇒ Object

Forwarder used by Resolver and Entry classes that received a Data but were written against the historical Manifest API.



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

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