Cuprum

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.

Class: Cuprum::ResultList

Parent Namespace
Cuprum
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

Constructor

#initialize(*results, allow_partial: false, error: UNDEFINED, status: UNDEFINED, value: UNDEFINED) => ResultList

Parameters

Returns

Back To Top

Instance Attributes

#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.

Returns

#results => Array<Cuprum::Result> (readonly)

Also known as: to_a

Returns

#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.

Returns

#value => Object (readonly)

Returns

Back To Top

Instance Methods

#==(other) => true, false

Returns

#allow_partial? => true, false

Returns

See Also

#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

#errors => Array<Cuprum::Error, nil>

Returns

#failure? => Boolean

Returns

#statuses => Array<Symbol>

Returns

#success? => Boolean

Returns

#to_cuprum_result => Cuprum::Result

Converts the result list to a Cuprum::Result.

Returns

See Also

#values => Array<Object, nil>

Returns

Back To Top


Back to Documentation | Reference | Cuprum