Class: Textus::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest.rb,
lib/textus/manifest/entry.rb,
lib/textus/manifest/rules.rb,
lib/textus/manifest/schema.rb,
lib/textus/manifest/resolver.rb,
lib/textus/manifest/entry/base.rb,
lib/textus/manifest/entry/leaf.rb,
lib/textus/manifest/resolution.rb,
lib/textus/manifest/entry/intake.rb,
lib/textus/manifest/entry/nested.rb,
lib/textus/manifest/entry/parser.rb,
lib/textus/manifest/entry/derived.rb,
lib/textus/manifest/entry/validators.rb,
lib/textus/manifest/entry/validators/events.rb,
lib/textus/manifest/entry/validators/inject_intro.rb,
lib/textus/manifest/entry/validators/publish_each.rb,
lib/textus/manifest/entry/validators/format_matrix.rb,
lib/textus/manifest/entry/validators/index_filename.rb

Defined Under Namespace

Modules: Schema Classes: Entry, Resolution, Resolver, Rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, raw) ⇒ Manifest

Returns a new instance of Manifest.

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/textus/manifest.rb', line 58

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

  Schema.validate!(raw)

  @entries = Array(raw["entries"]).map do |e|
    entry = Manifest::Entry::Parser.call(self, e)
    Manifest::Entry::Validators.run_all(entry)
    entry
  end
  validate_declared_keys!
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



8
9
10
# File 'lib/textus/manifest.rb', line 8

def entries
  @entries
end

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/textus/manifest.rb', line 8

def raw
  @raw
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/textus/manifest.rb', line 8

def root
  @root
end

Class Method Details

.load(root) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
# File 'lib/textus/manifest.rb', line 39

def self.load(root)
  manifest_path = File.join(root, "manifest.yaml")
  raise IoError.new("manifest not found: #{manifest_path}") unless File.exist?(manifest_path)

  raw = YAML.safe_load_file(manifest_path, aliases: false)
  check_version!(raw, manifest_path)
  new(root, raw)
end

.parse(yaml_text, root: ".") ⇒ Object



33
34
35
36
37
# File 'lib/textus/manifest.rb', line 33

def self.parse(yaml_text, root: ".")
  raw = YAML.safe_load(yaml_text, aliases: false)
  check_version!(raw, "<string>")
  new(root, raw)
end

Instance Method Details

#permission_for(zone_name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/textus/manifest.rb', line 25

def permission_for(zone_name)
  Textus::Domain::Permission.new(
    zone: zone_name,
    write_policy: zone_writers(zone_name),
    read_policy: zone_readers[zone_name] || :all,
  )
end

#resolverObject



81
82
83
# File 'lib/textus/manifest.rb', line 81

def resolver
  @resolver ||= Resolver.new(self)
end

#rulesObject



73
74
75
# File 'lib/textus/manifest.rb', line 73

def rules
  @rules ||= Textus::Manifest::Rules.parse(@raw["rules"] || [])
end

#rules_for(key) ⇒ Object



77
78
79
# File 'lib/textus/manifest.rb', line 77

def rules_for(key)
  rules.for(key)
end

#validate_key!(key) ⇒ Object

Raises:



85
86
87
88
89
# File 'lib/textus/manifest.rb', line 85

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

  Key::Grammar.validate!(key)
end

#zone_readersObject



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

def zone_readers
  @zone_readers ||= Array(@raw["zones"]).to_h do |z|
    rp = z["read_policy"]
    [z["name"], rp.nil? ? :all : Array(rp)]
  end
end

#zone_writers(zone_name) ⇒ Object



21
22
23
# File 'lib/textus/manifest.rb', line 21

def zone_writers(zone_name)
  zones[zone_name] or raise UsageError.new("undeclared zone '#{zone_name}'")
end

#zonesObject



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

def zones
  @zones ||= Array(@raw["zones"]).to_h { |z| [z["name"], Array(z["write_policy"])] }
end