Class: Textus::Manifest::Entry::Derived

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

Defined Under Namespace

Classes: External, Projection

Constant Summary collapse

KIND =
:derived

Constants inherited from Textus::Manifest::Entry

PUBLISH_EACH_VARS, PUBLISH_EACH_VAR_RE, REGISTRY

Instance Attribute Summary collapse

Attributes inherited from Base

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#in_generator_zone?, #in_proposal_zone?, #index_filename, #intake?, #leaf?, #nested?, #publish_each, #zone_writers

Constructor Details

#initialize(source:, template: nil, inject_boot: false, events: {}, **rest) ⇒ Derived

Returns a new instance of Derived.



10
11
12
13
14
15
16
# File 'lib/textus/manifest/entry/derived.rb', line 10

def initialize(source:, template: nil, inject_boot: false, events: {}, **rest)
  super(**rest)
  @source = source
  @template = template
  @inject_boot = inject_boot
  @events = events || {}
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



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

def events
  @events
end

#inject_bootObject (readonly)

Returns the value of attribute inject_boot.



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

def inject_boot
  @inject_boot
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Class Method Details

.from_raw(common, raw) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/textus/manifest/entry/derived.rb', line 46

def self.from_raw(common, raw)
  source = Parser.parse_source(raw, common[:key])
  new(
    source: source,
    template: raw["template"],
    inject_boot: raw["inject_boot"] == true,
    events: raw["events"] || {},
    **common,
  )
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


18
# File 'lib/textus/manifest/entry/derived.rb', line 18

def derived? = true

#external?Boolean

Returns:

  • (Boolean)


20
# File 'lib/textus/manifest/entry/derived.rb', line 20

def external?   = @source.is_a?(External)

#projection?Boolean

Returns:

  • (Boolean)


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

def projection? = @source.is_a?(Projection)

#publish_via(pctx, prefix: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/textus/manifest/entry/derived.rb', line 22

def publish_via(pctx, prefix: nil) # rubocop:disable Lint/UnusedMethodArgument
  return nil unless in_generator_zone?

  target_path = Textus::Application::Writes::Materializer.new(
    ctx: pctx.ctx, manifest: pctx.manifest, file_store: pctx.file_store,
    bus: pctx.bus, root: pctx.root, store: pctx.store
  ).run(self)

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

  src = @source
  selects = src.is_a?(Projection) ? Array(src.select).compact : []
  pctx.emit.call(:build_completed, key: @key, envelope: envelope, sources: selects)

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