aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/arel/collectors
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2018-02-24 17:04:15 +1030
committerMatthew Draper <matthew@trebex.net>2018-02-24 17:15:32 +1030
commit17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4 (patch)
tree38afd3ed74f8afda1c2959fefbc13f70b2e448e2 /activerecord/lib/arel/collectors
parent5ecbeda0e225e4961977b5c516088cf12d92319f (diff)
parenteb3f968b5ffdd3b343e7d190f1aa0b36864f56a2 (diff)
downloadrails-17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4.tar.gz
rails-17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4.tar.bz2
rails-17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4.zip
Merge Arel into Active Record
Diffstat (limited to 'activerecord/lib/arel/collectors')
-rw-r--r--activerecord/lib/arel/collectors/bind.rb24
-rw-r--r--activerecord/lib/arel/collectors/composite.rb32
-rw-r--r--activerecord/lib/arel/collectors/plain_string.rb19
-rw-r--r--activerecord/lib/arel/collectors/sql_string.rb24
-rw-r--r--activerecord/lib/arel/collectors/substitute_binds.rb28
5 files changed, 127 insertions, 0 deletions
diff --git a/activerecord/lib/arel/collectors/bind.rb b/activerecord/lib/arel/collectors/bind.rb
new file mode 100644
index 0000000000..d816aed90d
--- /dev/null
+++ b/activerecord/lib/arel/collectors/bind.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Arel
+ module Collectors
+ class Bind
+ def initialize
+ @binds = []
+ end
+
+ def << str
+ self
+ end
+
+ def add_bind bind
+ @binds << bind
+ self
+ end
+
+ def value
+ @binds
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/arel/collectors/composite.rb b/activerecord/lib/arel/collectors/composite.rb
new file mode 100644
index 0000000000..4f6156fe27
--- /dev/null
+++ b/activerecord/lib/arel/collectors/composite.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Arel
+ module Collectors
+ class Composite
+ def initialize(left, right)
+ @left = left
+ @right = right
+ end
+
+ def << str
+ left << str
+ right << str
+ self
+ end
+
+ def add_bind bind, &block
+ left.add_bind bind, &block
+ right.add_bind bind, &block
+ self
+ end
+
+ def value
+ [left.value, right.value]
+ end
+
+ protected
+
+ attr_reader :left, :right
+ end
+ end
+end
diff --git a/activerecord/lib/arel/collectors/plain_string.rb b/activerecord/lib/arel/collectors/plain_string.rb
new file mode 100644
index 0000000000..1e8d2a2152
--- /dev/null
+++ b/activerecord/lib/arel/collectors/plain_string.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+module Arel
+ module Collectors
+ class PlainString
+ def initialize
+ @str = ''.dup
+ end
+
+ def value
+ @str
+ end
+
+ def << str
+ @str << str
+ self
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/arel/collectors/sql_string.rb b/activerecord/lib/arel/collectors/sql_string.rb
new file mode 100644
index 0000000000..bcb941f6d4
--- /dev/null
+++ b/activerecord/lib/arel/collectors/sql_string.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require 'arel/collectors/plain_string'
+
+module Arel
+ module Collectors
+ class SQLString < PlainString
+ def initialize(*)
+ super
+ @bind_index = 1
+ end
+
+ def add_bind bind
+ self << yield(@bind_index)
+ @bind_index += 1
+ self
+ end
+
+ def compile bvs
+ value
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/arel/collectors/substitute_binds.rb b/activerecord/lib/arel/collectors/substitute_binds.rb
new file mode 100644
index 0000000000..99d2215aaa
--- /dev/null
+++ b/activerecord/lib/arel/collectors/substitute_binds.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+module Arel
+ module Collectors
+ class SubstituteBinds
+ def initialize(quoter, delegate_collector)
+ @quoter = quoter
+ @delegate = delegate_collector
+ end
+
+ def << str
+ delegate << str
+ self
+ end
+
+ def add_bind bind
+ self << quoter.quote(bind)
+ end
+
+ def value
+ delegate.value
+ end
+
+ protected
+
+ attr_reader :quoter, :delegate
+ end
+ end
+end