substitute_binds.rb 703 字节
Newer Older
1
# frozen_string_literal: true
M
Matthew Draper 已提交
2

M
Matthew Draper 已提交
3
module Arel # :nodoc: all
A
Aaron Patterson 已提交
4
  module Collectors
S
Sean Griffin 已提交
5
    class SubstituteBinds
6 7
      attr_accessor :preparable

8 9 10
      def initialize(quoter, delegate_collector)
        @quoter = quoter
        @delegate = delegate_collector
A
Aaron Patterson 已提交
11 12
      end

M
Matthew Draper 已提交
13
      def <<(str)
14
        delegate << str
A
Aaron Patterson 已提交
15 16 17
        self
      end

M
Matthew Draper 已提交
18
      def add_bind(bind)
19
        bind = bind.value_for_database if bind.respond_to?(:value_for_database)
20
        self << quoter.quote(bind)
A
Aaron Patterson 已提交
21 22
      end

23 24 25 26
      def add_binds(binds)
        self << binds.map { |bind| quoter.quote(bind) }.join(", ")
      end

27 28
      def value
        delegate.value
A
Aaron Patterson 已提交
29
      end
30

R
Ryuta Kamizono 已提交
31
      private
M
Matthew Draper 已提交
32
        attr_reader :quoter, :delegate
A
Aaron Patterson 已提交
33 34 35
    end
  end
end