aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/where.rb
blob: 608aaeb4b7f7fafe544a928f33a3625ae185bb5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Arel
  class Where < Compound
    attributes :relation, :predicate
    deriving :==

    def initialize(relation, *predicates, &block)
      predicate = block_given?? yield(relation) : predicates.shift
      @relation = predicates.empty?? relation : Where.new(relation, *predicates)
      @predicate = predicate.bind(@relation)
    end

    def wheres
      @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) }
    end
  end
end