Class: Plumb::Or

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/plumb/or.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composable

#>>, #[], #as_node, #build, #check, #defer, #generate, included, #invalid, #invoke, #match, #metadata, #not, #pipeline, #policy, #static, #to_json_schema, #to_s, #transform, #value, wrap, #|

Methods included from Callable

#parse, #resolve

Constructor Details

#initialize(left, right) ⇒ Or

Returns a new instance of Or.



11
12
13
14
15
16
# File 'lib/plumb/or.rb', line 11

def initialize(left, right)
  @left = left
  @right = right
  @children = [left, right].freeze
  freeze
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/plumb/or.rb', line 9

def children
  @children
end

Instance Method Details

#call(result) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/plumb/or.rb', line 22

def call(result)
  left_result = @left.call(result)
  return left_result if left_result.valid?

  right_result = @right.call(result)
  if right_result.valid?
    right_result
  else
    right_result.invalid(errors: [left_result.errors,
                                  right_result.errors].flatten)
  end
end