Class: Datacaster::OrNode

Inherits:
Base
  • Object
show all
Defined in:
lib/datacaster/or_node.rb

Instance Method Summary collapse

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(left, right) ⇒ OrNode

Returns a new instance of OrNode.



3
4
5
6
# File 'lib/datacaster/or_node.rb', line 3

def initialize(left, right)
  @left = left
  @right = right
end

Instance Method Details

#cast(object, runtime:) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/datacaster/or_node.rb', line 8

def cast(object, runtime:)
  left_result = @left.with_runtime(runtime).(object)

  return left_result if left_result.valid?

  @right.with_runtime(runtime).(object)
end

#inspectObject



16
17
18
# File 'lib/datacaster/or_node.rb', line 16

def inspect
  "#<Datacaster::OrNode L: #{@left.inspect} R: #{@right.inspect}>"
end