Class: Textus::Manifest::Entry

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) ⇒ Entry

Returns a new instance of Entry.



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

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"])
  reject_legacy_projection_keys!
  validate_format_matrix!
  validate_publish_each!
  validate_inject_intro!
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



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

def events
  @events
end

#fetchObject (readonly)

Returns the value of attribute fetch.



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

def fetch
  @fetch
end

#fetch_configObject (readonly)

Returns the value of attribute fetch_config.



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

def fetch_config
  @fetch_config
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#generatorObject (readonly)

Returns the value of attribute generator.



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

def generator
  @generator
end

#inject_introObject (readonly)

Returns the value of attribute inject_intro.



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

def inject_intro
  @inject_intro
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#nestedObject (readonly)

Returns the value of attribute nested.



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

def nested
  @nested
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#projectionObject (readonly)

Returns the value of attribute projection.



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

def projection
  @projection
end

#publish_eachObject (readonly)

Returns the value of attribute publish_each.



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

def publish_each
  @publish_each
end

#publish_toObject (readonly)

Returns the value of attribute publish_to.



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

def publish_to
  @publish_to
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

#ttlObject (readonly)

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

#zoneObject (readonly)

Returns the value of attribute zone.



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

def zone
  @zone
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/textus/manifest/entry.rb', line 56

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:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/textus/manifest/entry.rb', line 40

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 = Textus::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