Class: Textus::Manifest::Entry::Base

Inherits:
Textus::Manifest::Entry show all
Defined in:
lib/textus/manifest/entry/base.rb

Direct Known Subclasses

Derived, Intake, Leaf, Nested

Defined Under Namespace

Classes: PublishContext

Constant Summary

Constants inherited from Textus::Manifest::Entry

PUBLISH_EACH_VARS, PUBLISH_EACH_VAR_RE, REGISTRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest:, raw:, key:, path:, zone:, schema:, owner:, format:, publish_to: []) ⇒ Base

rubocop:disable Metrics/ParameterLists, Lint/MissingSuper



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/textus/manifest/entry/base.rb', line 8

def initialize(manifest:, raw:, key:, path:, zone:, schema:, owner:, format:, publish_to: [])
  @manifest = manifest
  @raw = raw
  @key = key
  @path = path
  @zone = zone
  @schema = schema
  @owner = owner
  @format = format
  @publish_to = Array(publish_to)
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def format
  @format
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def key
  @key
end

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def manifest
  @manifest
end

#ownerObject (readonly)

Returns the value of attribute owner.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def path
  @path
end

#publish_toObject (readonly)

Returns the value of attribute publish_to.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def publish_to
  @publish_to
end

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def raw
  @raw
end

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def schema
  @schema
end

#zoneObject (readonly)

Returns the value of attribute zone.



5
6
7
# File 'lib/textus/manifest/entry/base.rb', line 5

def zone
  @zone
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


31
# File 'lib/textus/manifest/entry/base.rb', line 31

def derived? = false

#eventsObject



40
# File 'lib/textus/manifest/entry/base.rb', line 40

def events         = {}

#in_generator_zone?Boolean

Returns:

  • (Boolean)


27
# File 'lib/textus/manifest/entry/base.rb', line 27

def in_generator_zone? = @manifest.zone_kinds(@zone).include?(:generator)

#in_proposal_zone?Boolean

Returns:

  • (Boolean)


28
# File 'lib/textus/manifest/entry/base.rb', line 28

def in_proposal_zone?  = @manifest.zone_kinds(@zone).include?(:proposer)

#index_filenameObject



42
# File 'lib/textus/manifest/entry/base.rb', line 42

def index_filename = nil

#inject_bootObject

rubocop:disable Naming/PredicateMethod



39
# File 'lib/textus/manifest/entry/base.rb', line 39

def inject_boot    = false # rubocop:disable Naming/PredicateMethod

#intake?Boolean

Returns:

  • (Boolean)


32
# File 'lib/textus/manifest/entry/base.rb', line 32

def intake?  = false

#leaf?Boolean

Returns:

  • (Boolean)


33
# File 'lib/textus/manifest/entry/base.rb', line 33

def leaf?    = false

#nested?Boolean

Returns:

  • (Boolean)


30
# File 'lib/textus/manifest/entry/base.rb', line 30

def nested?  = false

#publish_eachObject



41
# File 'lib/textus/manifest/entry/base.rb', line 41

def publish_each   = nil

#publish_via(pctx, prefix: nil) ⇒ Object

Subclasses override to customize publish behavior. Default: copy the stored file to each publish_to target. Returns: { kind: :built|:leaves, value: … } to be accumulated by Publish#call, or nil to skip.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/textus/manifest/entry/base.rb', line 54

def publish_via(pctx, prefix: nil) # rubocop:disable Lint/UnusedMethodArgument
  return nil if Array(publish_to).empty?

  source_path = pctx.manifest.resolver.resolve(@key).path
  envelope = pctx.reader.call(@key)

  publish_to.each do |rel|
    target_abs = File.join(pctx.repo_root, rel)
    Textus::Infra::Publisher.publish(source: source_path, target: target_abs, store_root: pctx.root)
    pctx.emit.call(:file_published,
                   key: @key,
                   envelope: envelope,
                   source: source_path,
                   target: target_abs)
  end

  { kind: :built, value: { "key" => @key, "path" => source_path, "published_to" => publish_to } }
end

#templateObject

Nil stubs for cross-cutting optional attrs. Subclasses override the ones they own. Validators and serializers can call these directly without ‘respond_to?` guards.



38
# File 'lib/textus/manifest/entry/base.rb', line 38

def template       = nil

#zone_writersObject

rubocop:enable Metrics/ParameterLists, Lint/MissingSuper



21
22
23
24
25
# File 'lib/textus/manifest/entry/base.rb', line 21

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