Class: Textus::ManifestEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest.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.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/textus/manifest.rb', line 205

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"])

  reject_legacy!(raw)
  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.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def action
  @action
end

#action_configObject (readonly)

Returns the value of attribute action_config.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def action_config
  @action_config
end

#eventsObject (readonly)

Returns the value of attribute events.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def events
  @events
end

#formatObject (readonly)

Returns the value of attribute format.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def format
  @format
end

#generatorObject (readonly)

Returns the value of attribute generator.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def generator
  @generator
end

#inject_introObject (readonly)

Returns the value of attribute inject_intro.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def inject_intro
  @inject_intro
end

#keyObject (readonly)

Returns the value of attribute key.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def key
  @key
end

#nestedObject (readonly)

Returns the value of attribute nested.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def nested
  @nested
end

#ownerObject (readonly)

Returns the value of attribute owner.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def path
  @path
end

#projectionObject (readonly)

Returns the value of attribute projection.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def projection
  @projection
end

#publish_eachObject (readonly)

Returns the value of attribute publish_each.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def publish_each
  @publish_each
end

#publish_toObject (readonly)

Returns the value of attribute publish_to.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def publish_to
  @publish_to
end

#rawObject (readonly)

Returns the value of attribute raw.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def raw
  @raw
end

#schemaObject (readonly)

Returns the value of attribute schema.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def schema
  @schema
end

#templateObject (readonly)

Returns the value of attribute template.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def template
  @template
end

#ttlObject (readonly)

Returns the value of attribute ttl.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def ttl
  @ttl
end

#zoneObject (readonly)

Returns the value of attribute zone.



201
202
203
# File 'lib/textus/manifest.rb', line 201

def zone
  @zone
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


249
250
251
252
253
254
# File 'lib/textus/manifest.rb', line 249

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:



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/textus/manifest.rb', line 233

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