aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/arel/visitors/where_sql.rb
blob: 8fb299d1c810d37d6f32543e71083a63db99f378 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Arel # :nodoc: all
  module Visitors
    class WhereSql < Arel::Visitors::ToSql
      def initialize(inner_visitor, *args, &block)
        @inner_visitor = inner_visitor
        super(*args, &block)
      end

      private
        def visit_Arel_Nodes_SelectCore(o, collector)
          collector << "WHERE "
          wheres = o.wheres.map do |where|
            Nodes::SqlLiteral.new(@inner_visitor.accept(where, collector.class.new).value)
          end

          inject_join wheres, collector, " AND "
        end
    end
  end
end