Class: Textus::Envelope
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Textus::Envelope
- Defined in:
- lib/textus/envelope.rb,
lib/textus/envelope/reader.rb,
lib/textus/envelope/writer.rb
Defined Under Namespace
Class Method Summary collapse
-
.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- .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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/textus/envelope.rb', line 22 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(), etag: etag, schema_ref: mentry.schema, meta: , body: body, content: content, freshness: freshness, ) end |
.extract_uid(meta) ⇒ Object
41 42 43 44 |
# File 'lib/textus/envelope.rb', line 41 def self.extract_uid() v = .is_a?(Hash) ? ["uid"] : nil v.is_a?(String) ? v : nil end |
Instance Method Details
#fetching? ⇒ Boolean
73 74 75 76 77 |
# File 'lib/textus/envelope.rb', line 73 def fetching? return false if freshness.nil? freshness.fetching == true end |
#stale? ⇒ Boolean
67 68 69 70 71 |
# File 'lib/textus/envelope.rb', line 67 def stale? return false if freshness.nil? freshness.stale == true end |
#to_h_for_wire ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/textus/envelope.rb', line 48 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["content"] = content unless content.nil? freshness&.to_h_for_wire&.each { |k, v| h[k] = v } h end |
#with(**attrs) ⇒ Object
46 |
# File 'lib/textus/envelope.rb', line 46 def with(**attrs) = self.class.new(to_h.merge(attrs)) |