Class: Datacaster::AndNode
Instance Method Summary collapse
- #cast(object, runtime:) ⇒ Object
-
#initialize(*casters) ⇒ AndNode
constructor
A new instance of AndNode.
- #inspect ⇒ Object
Methods included from Mixin
#&, #*, #call, #call_with_runtime, #cast_errors, #i18n_key, #i18n_map_keys, #i18n_scope, #i18n_vars, #then, #with_context, #with_object_context, #with_runtime, #|
Constructor Details
#initialize(*casters) ⇒ AndNode
Returns a new instance of AndNode.
3 4 5 |
# File 'lib/datacaster/and_node.rb', line 3 def initialize(*casters) @casters = casters end |
Instance Method Details
#cast(object, runtime:) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/datacaster/and_node.rb', line 7 def cast(object, runtime:) Datacaster.ValidResult( @casters.reduce(object) do |result, caster| caster_result = caster.with_runtime(runtime).(result) return caster_result unless caster_result.valid? caster_result.value end ) end |
#inspect ⇒ Object
17 18 19 |
# File 'lib/datacaster/and_node.rb', line 17 def inspect "#<Datacaster::AndNode casters: #{@casters.inspect}>" end |