Class: Arel::Nodes::Or

Inherits:
Object
  • Object
show all
Includes:
ArelExtensions::BooleanFunctions
Defined in:
lib/arel_extensions/boolean_functions.rb

Overview

For some reason, Arel’s And is properly defined as variadic (it stores @children, and hashes it all). However Arel’s Or is defined as binary, with only @left and @right, and hashing only @left and @right.

So reimplement its ctor and accessors.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ArelExtensions::BooleanFunctions

#and, #or, #then, #⋀, #⋁

Constructor Details

#initialize(*children) ⇒ Or

Returns a new instance of Or.



58
59
60
# File 'lib/arel_extensions/boolean_functions.rb', line 58

def initialize *children
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



48
49
50
# File 'lib/arel_extensions/boolean_functions.rb', line 48

def children
  @children
end

Class Method Details

.new(*children) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/arel_extensions/boolean_functions.rb', line 50

def self.new *children
  children =
    children.flatten.map { |c|
      c.is_a?(self) ? c.children : c
    }.flatten
  super(*children)
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/arel_extensions/boolean_functions.rb', line 79

def eql?(other)
  self.class == other.class &&
    children == other.children
end

#hashObject



75
76
77
# File 'lib/arel_extensions/boolean_functions.rb', line 75

def hash
  children.hash
end

#initialize_copy(other) ⇒ Object



62
63
64
65
# File 'lib/arel_extensions/boolean_functions.rb', line 62

def initialize_copy(other)
  super
  @children = other.children.copy if other.children
end

#leftObject



67
68
69
# File 'lib/arel_extensions/boolean_functions.rb', line 67

def left
  children.first
end

#rightObject



71
72
73
# File 'lib/arel_extensions/boolean_functions.rb', line 71

def right
  children[1]
end