Class: Arel::Predicates::Polyadic

Inherits:
Predicate
  • Object
show all
Defined in:
lib/arel/algebra/predicates.rb,
lib/arel/engines/sql/predicates.rb,
lib/arel/engines/memory/predicates.rb

Direct Known Subclasses

All, Any

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#and, #complement, #not, #or

Constructor Details

#initialize(*predicates) ⇒ Polyadic

Returns a new instance of Polyadic.



24
25
26
# File 'lib/arel/algebra/predicates.rb', line 24

def initialize(*predicates)
  @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.inject([]) do |predicates, operand|
      predicates << operator.new(operand1, operand)
    end
  )
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/arel/algebra/predicates.rb', line 41

def ==(other)
  same_elements?(@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



22
23
24
25
26
# File 'lib/arel/engines/memory/predicates.rb', line 22

def eval(row)
  predicates.send(compounder) do |operation|
    operation.eval(row)
  end
end

#to_sql(formatter = nil) ⇒ Object



34
35
36
37
38
# File 'lib/arel/engines/sql/predicates.rb', line 34

def to_sql(formatter = nil)
  "(" +
    predicates.map {|p| p.to_sql(formatter)}.join(" #{predicate_sql} ") +
  ")"
end