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.

Raises:



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

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!
  raise UsageError.new("entry '#{@key}': 'source:' key renamed to 'intake:' in 0.9") if raw.key?("source")

  parse_intake!(raw["intake"])
  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

#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

#intake_configObject (readonly)

Returns the value of attribute intake_config.



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

def intake_config
  @intake_config
end

#intake_handlerObject (readonly)

Returns the value of attribute intake_handler.



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

def intake_handler
  @intake_handler
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

#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

Legacy alias for in_generator_zone?. Retained because internal validation callers (and external tools) read more naturally as ‘derived?`.

Returns:

  • (Boolean)


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

def derived?
  in_generator_zone?
end

#in_generator_zone?Boolean

Signal-based zone-kind predicates: derive the “kind” of a zone from its writable_by signals rather than its literal name. This keeps detection working when users rename the default zones (canon/intake/pending/derived → identity/inbox/review/output, etc.).

Returns:

  • (Boolean)


63
64
65
# File 'lib/textus/manifest/entry.rb', line 63

def in_generator_zone?
  zone_writers.include?("build")
end

#in_proposal_zone?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/textus/manifest/entry.rb', line 67

def in_proposal_zone?
  zone_writers.include?("ai")
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:



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

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