Module: Dry::Transformer::Conditional
- Extended by:
- Registry
- Defined in:
- lib/dry/transformer/conditional.rb
Overview
Conditional transformation functions
Class Method Summary collapse
-
.guard(value, predicate, fn) ⇒ Mixed
Apply the transformation function to subject if the predicate returns true, or return un-modified.
-
.is(value, type, fn) ⇒ Object
Calls a function when type-check passes.
-
.not(value, fn) ⇒ Boolean
Negates the result of transformation.
Methods included from Registry
[], contain?, fetch, import, register, store
Class Method Details
.guard(value, predicate, fn) ⇒ Mixed
Apply the transformation function to subject if the predicate returns true, or return un-modified
51 52 53 |
# File 'lib/dry/transformer/conditional.rb', line 51 def self.guard(value, predicate, fn) predicate[value] ? fn[value] : value end |
.is(value, type, fn) ⇒ Object
Calls a function when type-check passes
71 72 73 |
# File 'lib/dry/transformer/conditional.rb', line 71 def self.is(value, type, fn) guard(value, -> v { v.is_a?(type) }, fn) end |
.not(value, fn) ⇒ Boolean
Negates the result of transformation
34 35 36 |
# File 'lib/dry/transformer/conditional.rb', line 34 def self.not(value, fn) !fn[value] end |