Class: Textus::ManifestEntry

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

Constant Summary collapse

PUBLISH_EACH_VARS =
%w[leaf basename key ext].freeze
PUBLISH_EACH_VAR_RE =
/\{([a-z]+)\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest, raw) ⇒ ManifestEntry

Returns a new instance of ManifestEntry.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/textus/manifest_entry.rb', line 10

def initialize(manifest, raw)
  @manifest = manifest
  @raw = raw
  @key = raw["key"] or raise UsageError.new("manifest entry missing key")
  @path = raw["path"] or raise UsageError.new("manifest entry '#{@key}' missing path")
  @zone = raw["zone"] or raise UsageError.new("manifest entry '#{@key}' missing zone")
  @schema = raw["schema"]
  @owner = raw["owner"]
  @nested = raw["nested"] == true
  @generator = raw["generator"]
  @projection = raw["projection"]
  @template = raw["template"]
  @publish_to = Array(raw["publish_to"])
  @publish_each = raw["publish_each"]
  @events = raw["events"] || {}
  @inject_intro = raw["inject_intro"] == true
  @format = resolve_format!(raw["format"])

  validate_events!
  parse_source!(raw["source"])
  validate_format_matrix!
  validate_publish_each!
  validate_inject_intro!
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def action
  @action
end

#action_configObject (readonly)

Returns the value of attribute action_config.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def action_config
  @action_config
end

#eventsObject (readonly)

Returns the value of attribute events.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def events
  @events
end

#formatObject (readonly)

Returns the value of attribute format.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def format
  @format
end

#generatorObject (readonly)

Returns the value of attribute generator.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def generator
  @generator
end

#inject_introObject (readonly)

Returns the value of attribute inject_intro.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def inject_intro
  @inject_intro
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def key
  @key
end

#nestedObject (readonly)

Returns the value of attribute nested.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def nested
  @nested
end

#ownerObject (readonly)

Returns the value of attribute owner.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def path
  @path
end

#projectionObject (readonly)

Returns the value of attribute projection.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def projection
  @projection
end

#publish_eachObject (readonly)

Returns the value of attribute publish_each.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def publish_each
  @publish_each
end

#publish_toObject (readonly)

Returns the value of attribute publish_to.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def publish_to
  @publish_to
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def raw
  @raw
end

#schemaObject (readonly)

Returns the value of attribute schema.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def schema
  @schema
end

#templateObject (readonly)

Returns the value of attribute template.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def template
  @template
end

#ttlObject (readonly)

Returns the value of attribute ttl.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def ttl
  @ttl
end

#zoneObject (readonly)

Returns the value of attribute zone.



6
7
8
# File 'lib/textus/manifest_entry.rb', line 6

def zone
  @zone
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/textus/manifest_entry.rb', line 54

def derived?
  writers = @manifest.zone_writers(@zone)
  writers.include?("build")
rescue UsageError => e
  raise UsageError.new("entry '#{@key}': #{e.message}")
end

#publish_target_for(full_key) ⇒ Object

Resolves the per-leaf target path (relative to repo root) for a full dotted key under this entry’s prefix. Returns nil if this entry has no publish_each template.

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/textus/manifest_entry.rb', line 38

def publish_target_for(full_key)
  return nil if @publish_each.nil?

  entry_segs = @key.split(".")
  key_segs = full_key.split(".")
  raise UsageError.new("key '#{full_key}' is not under entry '#{@key}'") unless key_segs[0, entry_segs.length] == entry_segs

  remaining = key_segs[entry_segs.length..] || []
  leaf = remaining.join("/")
  basename = remaining.last || ""
  ext = Entry.for_format(@format).extensions.first.to_s.sub(/^\./, "")

  vars = { "leaf" => leaf, "basename" => basename, "key" => full_key, "ext" => ext }
  @publish_each.gsub(PUBLISH_EACH_VAR_RE) { vars.fetch(::Regexp.last_match(1)) }
end