aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/value.rb
blob: 70e94e0ad0fff727c337077d401bd71934feb2ad (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Arel
  class Value
    attr_reader :value, :relation

    def initialize value, relation
      @value = value
      @relation = relation
    end

    def == other
      super ||
        Value === other &&
        value == other.value &&
        relation == other.relation
    end

    def eval(row)
      value
    end

    def bind(relation)
      Value.new(value, relation)
    end

    def to_ordering
      self
    end

    def inclusion_predicate_sql
      value.inclusion_predicate_sql
    end

    def exclusion_predicate_sql
      value.exclusion_predicate_sql
    end

    def equality_predicate_sql
      value.equality_predicate_sql
    end

    def inequality_predicate_sql
      value.inequality_predicate_sql
    end

    def to_sql(formatter = Sql::WhereCondition.new(relation))
      formatter.value value
    end

    def format(object)
      object.to_sql(Sql::Value.new(relation))
    end
  end
end