Module: Textus::Refresh
- Defined in:
- lib/textus/refresh.rb
Class Method Summary collapse
- .call(store, key, as:) ⇒ Object
-
.normalize_action_result(res, format:) ⇒ Object
Normalize the three accepted intake return shapes into the store’s internal body, content representation.
- .refresh_stale(store, prefix: nil, zone: nil, as: "script") ⇒ Object
Class Method Details
.call(store, key, as:) ⇒ Object
3 4 5 6 |
# File 'lib/textus/refresh.rb', line 3 def self.call(store, key, as:) ctx = Textus::Composition.context(store, role: as) Textus::Composition.refresh_worker(ctx).run(key) end |
.normalize_action_result(res, format:) ⇒ Object
Normalize the three accepted intake return shapes into the store’s internal body, content representation.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/textus/refresh.rb', line 15 def self.normalize_action_result(res, format:) res = res.transform_keys(&:to_s) if res.is_a?(Hash) res ||= {} = res["_meta"] body = res["body"] content = res["content"] case format when "markdown" { meta: || {}, body: body.to_s, content: nil } when "text" { meta: {}, body: body.to_s, content: nil } when "json", "yaml" if !content.nil? { meta: || {}, body: nil, content: content } elsif !body.nil? { meta: {}, body: body.to_s, content: nil } else raise UsageError.new("intake for #{format} returned neither content nor body") end else raise UsageError.new("unknown format #{format.inspect}") end end |
.refresh_stale(store, prefix: nil, zone: nil, as: "script") ⇒ Object
8 9 10 11 |
# File 'lib/textus/refresh.rb', line 8 def self.refresh_stale(store, prefix: nil, zone: nil, as: "script") ctx = Textus::Composition.context(store, role: as) Textus::Application::Refresh::All.call(ctx, prefix: prefix, zone: zone) end |