Class: Textus::Value::Envelope
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Textus::Value::Envelope
- Defined in:
- lib/textus/value/envelope.rb
Class Method Summary collapse
-
.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- .extract_sources(meta) ⇒ Object
- .extract_uid(meta) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/textus/value/envelope.rb', line 24 def self.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil) # rubocop:enable Metrics/ParameterLists new( protocol: Textus::PROTOCOL, key: key, lane: mentry.lane, owner: mentry.owner, path: path, format: mentry.format, uid: extract_uid(), sources: extract_sources(), etag: etag, schema_ref: mentry.schema, meta: , body: body, content: content, freshness: freshness, ) end |
.extract_sources(meta) ⇒ Object
49 50 51 52 |
# File 'lib/textus/value/envelope.rb', line 49 def self.extract_sources() v = .is_a?(Hash) ? ["sources"] : nil v.is_a?(Array) && !v.empty? ? v : nil end |
.extract_uid(meta) ⇒ Object
44 45 46 47 |
# File 'lib/textus/value/envelope.rb', line 44 def self.extract_uid() v = .is_a?(Hash) ? ["uid"] : nil v.is_a?(String) ? v : nil end |
Instance Method Details
#fetching? ⇒ Boolean
82 83 84 85 86 |
# File 'lib/textus/value/envelope.rb', line 82 def fetching? return false if freshness.nil? freshness.fetching == true end |
#stale? ⇒ Boolean
76 77 78 79 80 |
# File 'lib/textus/value/envelope.rb', line 76 def stale? return false if freshness.nil? freshness.stale == true end |
#to_h_for_wire ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/textus/value/envelope.rb', line 56 def to_h_for_wire h = { "protocol" => protocol, "key" => key, "lane" => lane, "owner" => owner, "path" => path, "format" => format, "_meta" => , "body" => body, "etag" => etag, "schema_ref" => schema_ref, "uid" => uid, } h["sources"] = sources if sources h["content"] = content unless content.nil? freshness&.to_h_for_wire&.each { |k, v| h[k] = v } h end |
#with(**attrs) ⇒ Object
54 |
# File 'lib/textus/value/envelope.rb', line 54 def with(**attrs) = self.class.new(to_h.merge(attrs)) |