Class: Textus::Domain::Policy::Source
- Inherits:
-
Object
- Object
- Textus::Domain::Policy::Source
- Defined in:
- lib/textus/domain/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: project -> derived (internal projection; observable -> rdeps staleness)
from: handler -> intake (external fetch; unobservable -> ttl staleness)
from: command -> external (out-of-band runner; staleness only, textus never runs it)
‘on_write` (sync|async, default async) is the write-trigger strategy for observable (project) sources; meaningless for intake/command.
Constant Summary collapse
- FROMS =
%w[project handler command].freeze
- STRATEGIES =
%w[async sync].freeze
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
- #external? ⇒ Boolean
-
#initialize(raw) ⇒ Source
constructor
A new instance of Source.
- #kind ⇒ Object
- #pluck ⇒ Object
- #projection? ⇒ Boolean
-
#projection_spec ⇒ Object
The projection spec hash fed to Textus::Projection (string keys, only the present fields).
-
#select ⇒ Object
Flattened projection accessors (ADR 0094) — read directly off the source block; nil when absent or not a projection source.
- #sort_by ⇒ Object
- #sync? ⇒ Boolean
- #transform ⇒ Object
- #ttl_seconds ⇒ Object
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 33 34 35 36 37 |
# File 'lib/textus/domain/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 @on_write = (raw["on_write"] || "async").to_s unless STRATEGIES.include?(@on_write) raise Textus::BadManifest.new("source.on_write must be one of #{STRATEGIES.join("/")}, got #{@on_write.inspect}") end @ttl = raw["ttl"] @projection = {} case @from when "project" then init_project(raw) when "handler" then init_handler(raw) when "command" then init_command(raw) end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
16 17 18 |
# File 'lib/textus/domain/policy/source.rb', line 16 def command @command end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/textus/domain/policy/source.rb', line 16 def config @config end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
16 17 18 |
# File 'lib/textus/domain/policy/source.rb', line 16 def from @from end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
16 17 18 |
# File 'lib/textus/domain/policy/source.rb', line 16 def handler @handler end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
16 17 18 |
# File 'lib/textus/domain/policy/source.rb', line 16 def sources @sources end |
Instance Method Details
#external? ⇒ Boolean
40 |
# File 'lib/textus/domain/policy/source.rb', line 40 def external? = @from == "command" |
#kind ⇒ Object
39 |
# File 'lib/textus/domain/policy/source.rb', line 39 def kind = @from == "handler" ? :intake : :derived |
#pluck ⇒ Object
48 |
# File 'lib/textus/domain/policy/source.rb', line 48 def pluck = @projection["pluck"] |
#projection? ⇒ Boolean
41 |
# File 'lib/textus/domain/policy/source.rb', line 41 def projection? = @from == "project" |
#projection_spec ⇒ Object
The projection spec hash fed to Textus::Projection (string keys, only the present fields). {} when not a projection.
54 |
# File 'lib/textus/domain/policy/source.rb', line 54 def projection_spec = @projection.dup |
#select ⇒ Object
Flattened projection accessors (ADR 0094) — read directly off the source block; nil when absent or not a projection source.
47 |
# File 'lib/textus/domain/policy/source.rb', line 47 def select = @projection["select"] |
#sort_by ⇒ Object
49 |
# File 'lib/textus/domain/policy/source.rb', line 49 def sort_by = @projection["sort_by"] |
#sync? ⇒ Boolean
42 |
# File 'lib/textus/domain/policy/source.rb', line 42 def sync? = @on_write == "sync" |
#transform ⇒ Object
50 |
# File 'lib/textus/domain/policy/source.rb', line 50 def transform = @projection["transform"] |