Module: ParamParam

Defined in:
lib/param_param.rb,
lib/param_param/std.rb,
lib/param_param/result.rb,
lib/param_param/actions.rb

Overview

It allows to define actions that transform hash values. Each actions is bound to a particular key and processes a value related to that key.

Actions could be chained and executed one by one. An actions receives a value from a previous action and is expected to return successful or failed result. A successful result contains a new value being the result of the processing. The new value is passed further in the chain to the next action. A failed result contains a message from an action saying why a particular value can’t be processed. Following actions in the chain are not executed.

Defined Under Namespace

Modules: ClassMethods, Std Classes: Actions, Failure, Result, Success

Constant Summary collapse

ALL_OF =

A chain of actions that are executed consecutively and pass a value from a previous action to the following one.

If some action fails the chain is broken and value stops being processed.

lambda do |fns, option|
    fns.reduce(Success.new(option)) { |result, fn| result.failure? ? result : fn.call(result.value) }
end.curry
ANY =

Always succeeds with the provided option.

lambda do |option|
  Success.new(option)
end

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



17
18
19
# File 'lib/param_param.rb', line 17

def self.included(base)
  base.extend(ClassMethods)
end