Class: Igniter::Store::Protocol::Receipt

Inherits:
Struct
  • Object
show all
Defined in:
lib/igniter/store/protocol/receipt.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#derivedObject

Returns the value of attribute derived

Returns:

  • (Object)

    the current value of derived



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def derived
  @derived
end

#errorsObject

Returns the value of attribute errors

Returns:

  • (Object)

    the current value of errors



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def errors
  @errors
end

#fact_idObject

Returns the value of attribute fact_id

Returns:

  • (Object)

    the current value of fact_id



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def fact_id
  @fact_id
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def key
  @key
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def kind
  @kind
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def name
  @name
end

#schema_versionObject

Returns the value of attribute schema_version

Returns:

  • (Object)

    the current value of schema_version



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def schema_version
  @schema_version
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def status
  @status
end

#storeObject

Returns the value of attribute store

Returns:

  • (Object)

    the current value of store



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def store
  @store
end

#value_hashObject

Returns the value of attribute value_hash

Returns:

  • (Object)

    the current value of value_hash



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def value_hash
  @value_hash
end

#warningsObject

Returns the value of attribute warnings

Returns:

  • (Object)

    the current value of warnings



6
7
8
# File 'lib/igniter/store/protocol/receipt.rb', line 6

def warnings
  @warnings
end

Class Method Details

.accepted(kind:, name:, warnings: [], derived: []) ⇒ Object



24
25
26
27
# File 'lib/igniter/store/protocol/receipt.rb', line 24

def self.accepted(kind:, name:, warnings: [], derived: [])
  new(schema_version: 1, kind: kind, status: :accepted,
      name: name, warnings: warnings, errors: [], derived: derived)
end

.append_accepted(history:, fact:, requested_key: nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/igniter/store/protocol/receipt.rb', line 54

def self.append_accepted(history:, fact:, requested_key: nil)
  warnings = []
  if requested_key && requested_key.to_s != fact.key.to_s
    warnings << "append key is metadata only in protocol v0; generated fact key returned"
  end

  new(
    schema_version: 1,
    kind:       :append_receipt,
    status:     :accepted,
    store:      history,
    key:        fact.key,
    fact_id:    fact.id,
    value_hash: fact.value_hash,
    warnings:   warnings,
    errors:     [],
    derived:    []
  )
end

.deduplicated(kind:, name:) ⇒ Object



34
35
36
37
# File 'lib/igniter/store/protocol/receipt.rb', line 34

def self.deduplicated(kind:, name:)
  new(schema_version: 1, kind: kind, status: :deduplicated,
      name: name, warnings: ["descriptor already registered"], errors: [], derived: [])
end

.rejection(message, kind: nil, name: nil) ⇒ Object



29
30
31
32
# File 'lib/igniter/store/protocol/receipt.rb', line 29

def self.rejection(message, kind: nil, name: nil)
  new(schema_version: 1, kind: kind, status: :rejected,
      name: name, warnings: [], errors: [message], derived: [])
end

.write_accepted(store:, key:, fact:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/igniter/store/protocol/receipt.rb', line 39

def self.write_accepted(store:, key:, fact:)
  new(
    schema_version: 1,
    kind:       :receipt,
    status:     :accepted,
    store:      store,
    key:        key,
    fact_id:    fact.id,
    value_hash: fact.value_hash,
    warnings:   [],
    errors:     [],
    derived:    []
  )
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


20
# File 'lib/igniter/store/protocol/receipt.rb', line 20

def accepted?     = status == :accepted

#deduplicated?Boolean

Returns:

  • (Boolean)


22
# File 'lib/igniter/store/protocol/receipt.rb', line 22

def deduplicated? = status == :deduplicated

#rejected?Boolean

Returns:

  • (Boolean)


21
# File 'lib/igniter/store/protocol/receipt.rb', line 21

def rejected?     = status == :rejected

#to_hObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/igniter/store/protocol/receipt.rb', line 74

def to_h
  {
    schema_version: schema_version,
    kind:           kind,
    status:         status,
    name:           name,
    store:          store,
    key:            key,
    fact_id:        fact_id,
    value_hash:     value_hash,
    warnings:       warnings,
    errors:         errors,
    derived:        derived
  }.compact
end

#to_json(*args) ⇒ Object



90
91
92
# File 'lib/igniter/store/protocol/receipt.rb', line 90

def to_json(*args)
  to_h.to_json(*args)
end