Class: Arel::Predicates::Polyadic
Direct Known Subclasses
All, Any
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.build(operator, operand1, *additional_operands) ⇒ Object
Build a Polyadic predicate based on: * operator
- The Predicate subclass that defines the type of operation (LessThan, Equality, etc) * operand1
- The left-hand operand (normally an Arel::Attribute) * additional_operands
- All possible right-hand operands.
Instance Method Summary
collapse
Methods inherited from Predicate
#and, #complement, #not, #or
Constructor Details
#initialize(*predicates) ⇒ Polyadic
24
25
26
|
# File 'lib/arel/algebra/predicates.rb', line 24
def initialize(*predicates)
@predicates = predicates
end
|
Instance Attribute Details
#predicates ⇒ Object
Returns the value of attribute predicates.
22
23
24
|
# File 'lib/arel/algebra/predicates.rb', line 22
def predicates
@predicates
end
|
Class Method Details
.build(operator, operand1, *additional_operands) ⇒ Object
Build a Polyadic predicate based on:
-
operator
- The Predicate subclass that defines the type of operation (LessThan, Equality, etc)
-
operand1
- The left-hand operand (normally an Arel::Attribute)
-
additional_operands
- All possible right-hand operands
33
34
35
36
37
38
39
|
# File 'lib/arel/algebra/predicates.rb', line 33
def self.build(operator, operand1, *additional_operands)
new(
*additional_operands.uniq.map do |operand|
operator.new(operand1, operand)
end
)
end
|
Instance Method Details
#==(other) ⇒ Object
41
42
43
|
# File 'lib/arel/algebra/predicates.rb', line 41
def ==(other)
super || predicates == other.predicates
end
|
#bind(relation) ⇒ Object
45
46
47
48
49
|
# File 'lib/arel/algebra/predicates.rb', line 45
def bind(relation)
self.class.new(
*predicates.map {|p| p.find_correlate_in(relation)}
)
end
|
#eval(row) ⇒ Object
51
52
53
54
55
|
# File 'lib/arel/algebra/predicates.rb', line 51
def eval(row)
predicates.send(compounder) do |operation|
operation.eval(row)
end
end
|
#to_sql(formatter = nil) ⇒ Object
57
58
59
60
61
|
# File 'lib/arel/algebra/predicates.rb', line 57
def to_sql(formatter = nil)
"(" +
predicates.map {|p| p.to_sql(formatter)}.join(" #{predicate_sql} ") +
")"
end
|