Class: Textus::Manifest::Entry::Nested

Inherits:
Base show all
Defined in:
lib/textus/manifest/entry/nested.rb

Constant Summary collapse

PUBLISH_EACH_VARS =
Validators::PublishEach::KNOWN_VARS
PUBLISH_EACH_VAR_RE =
Validators::PublishEach::VAR_RE

Instance Attribute Summary collapse

Attributes inherited from Base

#format, #key, #manifest, #owner, #path, #raw, #schema, #zone

Instance Method Summary collapse

Methods inherited from Base

#derived?, #in_generator_zone?, #in_proposal_zone?, #intake?, #kind, #leaf?, #zone_writers

Constructor Details

#initialize(index_filename: nil, publish_each: nil, publish_to: [], **rest) ⇒ Nested

Returns a new instance of Nested.



12
13
14
15
16
17
# File 'lib/textus/manifest/entry/nested.rb', line 12

def initialize(index_filename: nil, publish_each: nil, publish_to: [], **rest)
  super(**rest)
  @index_filename = index_filename
  @publish_each = publish_each
  @publish_to = Array(publish_to)
end

Instance Attribute Details

#index_filenameObject (readonly)

Returns the value of attribute index_filename.



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

def index_filename
  @index_filename
end

#publish_eachObject (readonly)

Returns the value of attribute publish_each.



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

def publish_each
  @publish_each
end

#publish_toObject (readonly)

Returns the value of attribute publish_to.



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

def publish_to
  @publish_to
end

Instance Method Details

#nested?Boolean

Returns:

  • (Boolean)


19
# File 'lib/textus/manifest/entry/nested.rb', line 19

def nested? = true

#publish_target_for(full_key) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/textus/manifest/entry/nested.rb', line 21

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