Class: Printavo::ResponseEnvelope
- Inherits:
-
Object
- Object
- Printavo::ResponseEnvelope
- Defined in:
- lib/printavo/response_envelope.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(data:, errors: [], metadata: {}) ⇒ ResponseEnvelope
constructor
A new instance of ResponseEnvelope.
- #partial? ⇒ Boolean
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(data:, errors: [], metadata: {}) ⇒ ResponseEnvelope
Returns a new instance of ResponseEnvelope.
8 9 10 11 12 13 |
# File 'lib/printavo/response_envelope.rb', line 8 def initialize(data:, errors: [], metadata: {}) @data = immutable_copy(data) @errors = immutable_copy(errors) @metadata = immutable_copy() freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/printavo/response_envelope.rb', line 6 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/printavo/response_envelope.rb', line 6 def errors @errors end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/printavo/response_envelope.rb', line 6 def @metadata end |
Instance Method Details
#partial? ⇒ Boolean
19 20 21 |
# File 'lib/printavo/response_envelope.rb', line 19 def partial? !data.nil? && errors.any? end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/printavo/response_envelope.rb', line 15 def success? errors.empty? end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/printavo/response_envelope.rb', line 23 def to_h { 'data' => data, 'errors' => errors, 'metadata' => }.freeze end |