aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/primitives/value.rb
blob: 8ed3c4ce30af9de03a4c246eb640d8a48586a143 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Arel
  class Value
    attr_reader :value, :relation
    
    delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value
    
    def initialize(value, relation)
      @value, @relation = value, relation
    end
    
    def to_sql(formatter = Sql::WhereCondition.new(relation))
      formatter.value value
    end

    def format(object)
      object.to_sql(Sql::Value.new(relation))
    end
    
    def ==(other)
      self.class == other.class and
      value      == other.value
    end
    
    def bind(relation)
      Value.new(value, relation)
    end
  end
end