Class: Cuprum::ResultList
- Parent Namespace
- Cuprum
- Inherited Classes
- Cuprum::Result
>
Object
- Extended Modules
- Forwardable
- Included Modules
- Enumerable
- Defined In
- lib/cuprum/result_list.rb
Table Of Contents
Overview
Collection object that encapsulates a set of Cuprum results.
Each Cuprum::ResultList wraps an Array of Cuprum::Result objects, and itself
implements the same methods as a Result: #status, #value, #error, and the
#success? and #failure? predicates. As such, a Command’s #process method can
return a ResultList instead of a Result. This is useful for commands that
operate on a collection of items, such as a MapCommand or a controller
endpoint that performs a bulk operation.
See Also
Back To Top
Constants
STATUSES
= %i[success failure].freeze
- Inherited From
- Cuprum::Result
Enumerates the default permitted values for a Result#status.
Back To Top
Class Methods
- Inherited From
- Cuprum::Result
Returns
- Inherited From
- Cuprum::Result
Returns
Back To Top
Constructor
#initialize(*results, allow_partial: false, error: UNDEFINED, status: UNDEFINED, value: UNDEFINED) => ResultList
Parameters
- allow_partial (true, false) — If true, allows for some failing
results as long as there is at least one passing result. Defaults to
false.
- error (Cuprum::Error) — If given, sets the error for the result list
to the specified error object.
- results (Array<Cuprum::Result>) — The wrapped results.
- status (:success, :failure) — If given, sets the status of the result
list to the specified value.
- value (Object) — The value of the result. Defaults to the mapped
values of the results.
Returns
- (ResultList) — a new instance of ResultList
Back To Top
Instance Attributes
#error => Object (readonly)
- Inherited From
- Cuprum::Result
Returns
- (Object) — the error (if any) generated when the command was
called.
#results => Array<Cuprum::Result> (readonly)
Also known as:
to_a
Returns
#status => Symbol (readonly)
- Inherited From
- Cuprum::Result
Returns
- (Symbol) — the status of the result, either :success or :failure.
#value => Object (readonly)
- Inherited From
- Cuprum::Result
Returns
- (Object) — the value returned by calling the command.
Back To Top
Instance Methods
#==(other) => true, false
Returns
- (true, false) — true if the other object is a ResultList with
matching results and options; otherwise false.
#allow_partial? => true, false
Returns
- (true, false) — if true, allows for some failing results as long as
there is at least one passing result. Defaults to false.
See Also
- #status
- #to_cuprum_result
#each() => Enumerator
#each(&block) => Object
Iterates over the results.
Overloads
#each() => Enumerator
Returns
- (Enumerator) — an enumerator over the results.
#each(&block) => Object
Yields each result to the block.
Yield Parameters
Returns
- (Array<Cuprum::Error, nil>) — the error, if any, for each result.
#failure? => Boolean
- Inherited From
- Cuprum::Result
Returns
- (Boolean) — true if the result status is :failure, otherwise false.
#properties => Hash{Symbol => Object}
Also known as:
to_h
- Inherited From
- Cuprum::Result
Returns
- (Hash{Symbol => Object}) — a Hash representation of the result.
#statuses => Array<Symbol>
Returns
- (Array<Symbol>) — the status for each result.
#success? => Boolean
- Inherited From
- Cuprum::Result
Returns
- (Boolean) — true if the result status is :success, otherwise false.
- Inherited From
- Cuprum::Result
Returns
#values => Array<Object, nil>
Returns
- (Array<Object, nil>) — the value, if any, for each result.
Back To Top
Back to
Documentation |
Reference
|
Cuprum