Class: Textus::Envelope

Inherits:
Data
  • Object
show all
Defined in:
lib/textus/envelope.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



4
5
6
# File 'lib/textus/envelope.rb', line 4

def body
  @body
end

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



4
5
6
# File 'lib/textus/envelope.rb', line 4

def content
  @content
end

#etagObject (readonly)

Returns the value of attribute etag

Returns:

  • (Object)

    the current value of etag



4
5
6
# File 'lib/textus/envelope.rb', line 4

def etag
  @etag
end

#formatObject (readonly)

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



4
5
6
# File 'lib/textus/envelope.rb', line 4

def format
  @format
end

#freshnessObject (readonly)

Returns the value of attribute freshness

Returns:

  • (Object)

    the current value of freshness



4
5
6
# File 'lib/textus/envelope.rb', line 4

def freshness
  @freshness
end

#keyObject (readonly)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



4
5
6
# File 'lib/textus/envelope.rb', line 4

def key
  @key
end

#metaObject (readonly)

Returns the value of attribute meta

Returns:

  • (Object)

    the current value of meta



4
5
6
# File 'lib/textus/envelope.rb', line 4

def meta
  @meta
end

#ownerObject (readonly)

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



4
5
6
# File 'lib/textus/envelope.rb', line 4

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/textus/envelope.rb', line 4

def path
  @path
end

#protocolObject (readonly)

Returns the value of attribute protocol

Returns:

  • (Object)

    the current value of protocol



4
5
6
# File 'lib/textus/envelope.rb', line 4

def protocol
  @protocol
end

#schema_refObject (readonly)

Returns the value of attribute schema_ref

Returns:

  • (Object)

    the current value of schema_ref



4
5
6
# File 'lib/textus/envelope.rb', line 4

def schema_ref
  @schema_ref
end

#uidObject (readonly)

Returns the value of attribute uid

Returns:

  • (Object)

    the current value of uid



4
5
6
# File 'lib/textus/envelope.rb', line 4

def uid
  @uid
end

#zoneObject (readonly)

Returns the value of attribute zone

Returns:

  • (Object)

    the current value of zone



4
5
6
# File 'lib/textus/envelope.rb', line 4

def zone
  @zone
end

Class Method Details

.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/textus/envelope.rb', line 9

def self.build(key:, mentry:, path:, meta:, body:, etag:, content: nil, freshness: nil)
  # rubocop:enable Metrics/ParameterLists
  new(
    protocol: Textus::PROTOCOL,
    key: key,
    zone: mentry.zone,
    owner: mentry.owner,
    path: path,
    format: mentry.format,
    uid: extract_uid(meta),
    etag: etag,
    schema_ref: mentry.schema,
    meta: meta,
    body: body,
    content: content,
    freshness: freshness,
  )
end

.extract_uid(meta) ⇒ Object



28
29
30
31
# File 'lib/textus/envelope.rb', line 28

def self.extract_uid(meta)
  v = meta.is_a?(Hash) ? meta["uid"] : nil
  v.is_a?(String) ? v : nil
end

Instance Method Details

#refreshing?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/textus/envelope.rb', line 56

def refreshing?
  freshness.is_a?(Hash) && (freshness["refreshing"] == true || freshness[:refreshing] == true)
end

#stale?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/textus/envelope.rb', line 52

def stale?
  freshness.is_a?(Hash) && (freshness["stale"] == true || freshness[:stale] == true)
end

#to_h_for_wireObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/textus/envelope.rb', line 33

def to_h_for_wire
  h = {
    "protocol" => protocol,
    "key" => key,
    "zone" => zone,
    "owner" => owner,
    "path" => path,
    "format" => format,
    "_meta" => meta,
    "body" => body,
    "etag" => etag,
    "schema_ref" => schema_ref,
    "uid" => uid,
  }
  h["content"] = content unless content.nil?
  freshness.each { |k, v| h[k.to_s] = v } if freshness.is_a?(Hash)
  h
end