Module: Textus::Builder::InjectMeta

Defined in:
lib/textus/builder/pipeline.rb

Class Method Summary collapse

Class Method Details

.call(content_hash, mentry) ⇒ Object

Returns a new hash with _meta as the first key, per SPEC §6 ordering.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/textus/builder/pipeline.rb', line 8

def self.call(content_hash, mentry)
  meta = { "generated_at" => Time.now.utc.iso8601 }
  from = Array(mentry.projection&.fetch("select", nil)).compact
  meta["from"] = from unless from.empty?
  meta["template"] = mentry.template if mentry.template
  reduce = mentry.projection&.dig("reduce")
  meta["reduce"] = reduce if reduce

  out = { "_meta" => meta }
  content_hash.each { |k, v| out[k] = v unless k == "_meta" }
  out
end