An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.
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.
#initialize(*results, allow_partial: false, error: UNDEFINED, status: UNDEFINED, value: UNDEFINED) => ResultList
#error => Cuprum::Errors::MultipleErrors, Cuprum::Error, nil (readonly)
Returns the error for the result list.
If the result list was initialized with an error, returns that error.
If any of the results have errors, aggregates the result errors into a Cuprum::MultipleErrors object.
If none of the results have errors, returns nil.
#results => Array<Cuprum::Result> (readonly)
Also known as:
to_a
#status => :success, :failure (readonly)
Determines the status of the combined results.
If the result list was initialize with a status, returns that status.
If there are no failing results, i.e. the results array is empty or all of the results are passing, returns :success.
If there is at least one failing result, it instead returns :failure.
If the :allow_partial flag is set to true, returns :success if the results array is empty or there is at least one passing result. If there is at least one failing result and no passing results, it instead returns :failure.
#value => Object (readonly)
#==(other) => true, false
#allow_partial? => true, false
#each() => Enumerator#each(&block) => ObjectIterates over the results.
#each() => Enumerator
#each(&block) => Object
Yields each result to the block.
#errors => Array<Cuprum::Error, nil>
#failure? => Boolean
#statuses => Array<Symbol>
#success? => Boolean
#to_cuprum_result => Cuprum::Result
Converts the result list to a Cuprum::Result.
#values => Array<Object, nil>
Back to Documentation | Reference | Cuprum