aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes/extract.rb
blob: 64f5c3ff0f83e61780d05c682f67f0a497bdb74e (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
module Arel
  module Nodes
    class Extract < Arel::Nodes::Unary
      include Arel::Predications

      attr_accessor :field
      attr_accessor :alias

      def initialize expr, field, aliaz = nil
        super(expr)
        @field = field
        @alias = aliaz && SqlLiteral.new(aliaz)
      end

      def as aliaz
        self.alias = SqlLiteral.new(aliaz)
        self
      end

      def hash
        super ^ [@field, @alias].hash
      end

      def eql? other
        super &&
          self.field == other.field &&
          self.alias == other.alias
      end
      alias :== :eql?
    end
  end
end