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.



60
61
62
# File 'lib/arel_extensions/boolean_functions.rb', line 60

def initialize *children
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



50
51
52
# File 'lib/arel_extensions/boolean_functions.rb', line 50

def children
  @children
end

Class Method Details

.new(*children) ⇒ Object



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

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)


81
82
83
84
# File 'lib/arel_extensions/boolean_functions.rb', line 81

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

#hashObject



77
78
79
# File 'lib/arel_extensions/boolean_functions.rb', line 77

def hash
  children.hash
end

#initialize_copy(other) ⇒ Object



64
65
66
67
# File 'lib/arel_extensions/boolean_functions.rb', line 64

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

#leftObject



69
70
71
# File 'lib/arel_extensions/boolean_functions.rb', line 69

def left
  children.first
end

#rightObject



73
74
75
# File 'lib/arel_extensions/boolean_functions.rb', line 73

def right
  children[1]
end