Class: StandardLedger::Result
- Inherits:
-
Object
- Object
- StandardLedger::Result
- Defined in:
- lib/standard_ledger/result.rb
Overview
The gem’s default result type, returned by ‘StandardLedger.post` and `StandardLedger.rebuild!` when the host has not configured an adapter for its own Result class.
Hosts with their own Result type (e.g. ‘ApplicationOperation::Result`) register a translator via `StandardLedger.config.result_adapter` so the gem returns the host’s type instead — see ‘Config#result_adapter`.
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#projections ⇒ Object
readonly
Returns the value of attribute projections.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .failure(errors:, entry: nil, projections: {}) ⇒ Object
-
.success(entry:, idempotent: false, projections: {}) ⇒ Object
Build a successful result.
Instance Method Summary collapse
- #failure? ⇒ Boolean
- #idempotent? ⇒ Boolean
-
#initialize(success:, value: nil, errors: [], entry: nil, idempotent: false, projections: {}) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
Constructor Details
#initialize(success:, value: nil, errors: [], entry: nil, idempotent: false, projections: {}) ⇒ Result
Returns a new instance of Result.
20 21 22 23 24 25 26 27 |
# File 'lib/standard_ledger/result.rb', line 20 def initialize(success:, value: nil, errors: [], entry: nil, idempotent: false, projections: {}) @success = success @value = value @errors = errors @entry = entry @idempotent = idempotent @projections = projections end |
Instance Attribute Details
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
10 11 12 |
# File 'lib/standard_ledger/result.rb', line 10 def entry @entry end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/standard_ledger/result.rb', line 10 def errors @errors end |
#projections ⇒ Object (readonly)
Returns the value of attribute projections.
10 11 12 |
# File 'lib/standard_ledger/result.rb', line 10 def projections @projections end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/standard_ledger/result.rb', line 10 def value @value end |
Class Method Details
.failure(errors:, entry: nil, projections: {}) ⇒ Object
47 48 49 |
# File 'lib/standard_ledger/result.rb', line 47 def self.failure(errors:, entry: nil, projections: {}) new(success: false, errors: Array(errors), entry: entry, projections: projections) end |
.success(entry:, idempotent: false, projections: {}) ⇒ Object
Build a successful result. Convenience for ‘StandardLedger.post` and internal callers; not intended as the host’s primary construction path.
43 44 45 |
# File 'lib/standard_ledger/result.rb', line 43 def self.success(entry:, idempotent: false, projections: {}) new(success: true, value: entry, entry: entry, idempotent: idempotent, projections: projections) end |
Instance Method Details
#failure? ⇒ Boolean
33 34 35 |
# File 'lib/standard_ledger/result.rb', line 33 def failure? !@success end |
#idempotent? ⇒ Boolean
37 38 39 |
# File 'lib/standard_ledger/result.rb', line 37 def idempotent? @idempotent end |
#success? ⇒ Boolean
29 30 31 |
# File 'lib/standard_ledger/result.rb', line 29 def success? @success end |