Method: ParamParam::Actions#call
- Defined in:
- lib/param_param/actions.rb
#call(params) ⇒ Object
It takes a hash and processes values related to a key by an action assigned to the same key.
It returns two hashes:
-
if a value related to a key can be procesed by an action, the result is bound to the key and added to the first params hash
-
if a value related to a key can’t be processed by an action, the error is bound to the key and added to the last errors hash
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/param_param/actions.rb', line 30 def call(params) results = actions.to_h do |key, fn| option = params.key?(key) ? optionize(params[key]) : Optiomist.none [key, fn.call(option)] end errors = results.select { |_, result| result.failure? } .transform_values(&:error) params = results.select { |_, result| result.success? && result.value.some? } .transform_values { |result| result.value.value } [params, errors] end |