1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Place PartialQuery and PartialQueryCollector in the same file

This commit is contained in:
Ryuta Kamizono 2018-09-30 22:44:37 +09:00
parent 859fba7c4b
commit df9c972afe
2 changed files with 28 additions and 24 deletions

View file

@ -35,7 +35,7 @@ module ActiveRecord
sql, binds = visitor.compile(arel.ast, collector)
query = klass.query(sql)
else
collector = PartialQueryCollector.new
collector = klass.partial_query_collector
parts, binds = visitor.compile(arel.ast, collector)
query = klass.partial_query(parts)
end
@ -507,28 +507,6 @@ module ActiveRecord
value
end
end
class PartialQueryCollector
def initialize
@parts = []
@binds = []
end
def <<(str)
@parts << str
self
end
def add_bind(obj)
@binds << obj
@parts << Arel::Nodes::BindParam.new(1)
self
end
def value
[@parts, @binds]
end
end
end
end
end

View file

@ -44,7 +44,7 @@ module ActiveRecord
def initialize(values)
@values = values
@indexes = values.each_with_index.find_all { |thing, i|
Arel::Nodes::BindParam === thing
Substitute === thing
}.map(&:last)
end
@ -56,6 +56,28 @@ module ActiveRecord
end
end
class PartialQueryCollector
def initialize
@parts = []
@binds = []
end
def <<(str)
@parts << str
self
end
def add_bind(obj)
@binds << obj
@parts << Substitute.new
self
end
def value
[@parts, @binds]
end
end
def self.query(sql)
Query.new(sql)
end
@ -64,6 +86,10 @@ module ActiveRecord
PartialQuery.new(values)
end
def self.partial_query_collector
PartialQueryCollector.new
end
class Params # :nodoc:
def bind; Substitute.new; end
end