Class: Textus::Manifest::Policy::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest/policy/source.rb

Overview

An entry’s data-acquisition declaration (ADR 0094). ‘source:` says HOW the entry’s data is acquired; rendering is a publish concern, so there are no template/render fields here. ‘from` is the acquire + staleness axis:

from: derive -> derived   (internal projection; observable -> rdeps staleness)
from: fetch -> intake     (external fetch; unobservable -> ttl staleness)
from: external -> external (out-of-band runner; staleness only, textus never runs it)

Materialization is async-only (job-queue model): a write enqueues a ‘materialize` job, converged by a worker. There is no per-entry write trigger knob.

Constant Summary collapse

FROMS =
%w[fetch derive external].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Source

Returns a new instance of Source.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/textus/manifest/policy/source.rb', line 18

def initialize(raw)
  @from = raw["from"].to_s
  unless FROMS.include?(@from)
    raise Textus::BadManifest.new("source.from must be one of #{FROMS.join("|")}, got #{raw["from"].inspect}")
  end

  @ttl = raw["ttl"]
  @projection = {}

  case @from
  when "fetch" then init_fetch(raw)
  when "derive" then init_derive(raw)
  when "external" then init_external(raw)
  end
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



16
17
18
# File 'lib/textus/manifest/policy/source.rb', line 16

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/textus/manifest/policy/source.rb', line 16

def config
  @config
end

#fromObject (readonly)

Returns the value of attribute from.



16
17
18
# File 'lib/textus/manifest/policy/source.rb', line 16

def from
  @from
end

#handlerObject (readonly)

Returns the value of attribute handler.



16
17
18
# File 'lib/textus/manifest/policy/source.rb', line 16

def handler
  @handler
end

#sourcesObject (readonly)

Returns the value of attribute sources.



16
17
18
# File 'lib/textus/manifest/policy/source.rb', line 16

def sources
  @sources
end

Instance Method Details

#derive?Boolean

Returns:

  • (Boolean)


39
# File 'lib/textus/manifest/policy/source.rb', line 39

def derive?     = @from == "derive"

#external?Boolean

Returns:

  • (Boolean)


40
# File 'lib/textus/manifest/policy/source.rb', line 40

def external?   = @from == "external"

#fetch?Boolean

Returns:

  • (Boolean)


38
# File 'lib/textus/manifest/policy/source.rb', line 38

def fetch?      = @from == "fetch"

#kindObject



34
35
36
# File 'lib/textus/manifest/policy/source.rb', line 34

def kind
  { "fetch" => :intake, "derive" => :derived, "external" => :external }.fetch(@from)
end

#pluckObject



47
# File 'lib/textus/manifest/policy/source.rb', line 47

def pluck     = @projection["pluck"]

#projection?Boolean

Returns:

  • (Boolean)


41
# File 'lib/textus/manifest/policy/source.rb', line 41

def projection? = derive?

#projection_specObject

The projection spec hash fed to Textus::Projection (string keys, only the present fields). {} when not a projection.



53
# File 'lib/textus/manifest/policy/source.rb', line 53

def projection_spec = @projection.dup

#selectObject

Flattened projection accessors (ADR 0094) — read directly off the source block; nil when absent or not a projection source.



46
# File 'lib/textus/manifest/policy/source.rb', line 46

def select    = @projection["select"]

#sort_byObject



48
# File 'lib/textus/manifest/policy/source.rb', line 48

def sort_by   = @projection["sort_by"]

#transformObject



49
# File 'lib/textus/manifest/policy/source.rb', line 49

def transform = @projection["transform"]

#ttl_secondsObject



42
# File 'lib/textus/manifest/policy/source.rb', line 42

def ttl_seconds = @ttl.nil? ? nil : Textus::Core::Duration.seconds(@ttl)