arel 6.0.0.beta2 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +1 -1
  3. data/README.markdown +5 -5
  4. data/lib/arel.rb +1 -1
  5. data/lib/arel/collectors/sql_string.rb +7 -1
  6. data/lib/arel/expressions.rb +5 -4
  7. data/lib/arel/nodes.rb +1 -0
  8. data/lib/arel/nodes/bind_param.rb +6 -0
  9. data/lib/arel/nodes/sql_literal.rb +0 -3
  10. data/lib/arel/predications.rb +2 -2
  11. data/lib/arel/visitors/depth_first.rb +6 -0
  12. data/lib/arel/visitors/oracle.rb +4 -0
  13. data/lib/arel/visitors/postgresql.rb +4 -0
  14. data/lib/arel/visitors/reduce.rb +4 -4
  15. data/lib/arel/visitors/to_sql.rb +3 -2
  16. data/lib/arel/visitors/visitor.rb +15 -15
  17. metadata +26 -69
  18. data/.gitignore +0 -9
  19. data/.travis.yml +0 -18
  20. data/Gemfile +0 -5
  21. data/Rakefile +0 -15
  22. data/arel.gemspec +0 -24
  23. data/test/attributes/test_attribute.rb +0 -910
  24. data/test/collectors/test_bind_collector.rb +0 -70
  25. data/test/collectors/test_sql_string.rb +0 -38
  26. data/test/helper.rb +0 -22
  27. data/test/nodes/test_and.rb +0 -20
  28. data/test/nodes/test_as.rb +0 -34
  29. data/test/nodes/test_ascending.rb +0 -44
  30. data/test/nodes/test_bin.rb +0 -33
  31. data/test/nodes/test_binary.rb +0 -26
  32. data/test/nodes/test_count.rb +0 -33
  33. data/test/nodes/test_delete_statement.rb +0 -34
  34. data/test/nodes/test_descending.rb +0 -44
  35. data/test/nodes/test_distinct.rb +0 -20
  36. data/test/nodes/test_equality.rb +0 -84
  37. data/test/nodes/test_extract.rb +0 -41
  38. data/test/nodes/test_false.rb +0 -20
  39. data/test/nodes/test_grouping.rb +0 -25
  40. data/test/nodes/test_infix_operation.rb +0 -40
  41. data/test/nodes/test_insert_statement.rb +0 -42
  42. data/test/nodes/test_named_function.rb +0 -46
  43. data/test/nodes/test_node.rb +0 -39
  44. data/test/nodes/test_not.rb +0 -29
  45. data/test/nodes/test_or.rb +0 -34
  46. data/test/nodes/test_over.rb +0 -67
  47. data/test/nodes/test_select_core.rb +0 -69
  48. data/test/nodes/test_select_statement.rb +0 -49
  49. data/test/nodes/test_sql_literal.rb +0 -73
  50. data/test/nodes/test_sum.rb +0 -24
  51. data/test/nodes/test_table_alias.rb +0 -36
  52. data/test/nodes/test_true.rb +0 -21
  53. data/test/nodes/test_update_statement.rb +0 -58
  54. data/test/nodes/test_window.rb +0 -79
  55. data/test/support/fake_record.rb +0 -135
  56. data/test/test_attributes.rb +0 -66
  57. data/test/test_crud.rb +0 -63
  58. data/test/test_delete_manager.rb +0 -42
  59. data/test/test_factory_methods.rb +0 -44
  60. data/test/test_insert_manager.rb +0 -171
  61. data/test/test_select_manager.rb +0 -1181
  62. data/test/test_table.rb +0 -253
  63. data/test/test_update_manager.rb +0 -124
  64. data/test/visitors/test_bind_visitor.rb +0 -60
  65. data/test/visitors/test_depth_first.rb +0 -258
  66. data/test/visitors/test_dispatch_contamination.rb +0 -22
  67. data/test/visitors/test_dot.rb +0 -76
  68. data/test/visitors/test_ibm_db.rb +0 -33
  69. data/test/visitors/test_informix.rb +0 -58
  70. data/test/visitors/test_mssql.rb +0 -70
  71. data/test/visitors/test_mysql.rb +0 -60
  72. data/test/visitors/test_oracle.rb +0 -170
  73. data/test/visitors/test_postgres.rb +0 -122
  74. data/test/visitors/test_sqlite.rb +0 -23
  75. data/test/visitors/test_to_sql.rb +0 -598
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 574ad2e118c98249afe11b53301402b5147f4c30
4
- data.tar.gz: 57ffac4daf00d333d7e7f7e892a1803e000d3c92
3
+ metadata.gz: 607f322b2e6662d91cbef8d1433904774af2584c
4
+ data.tar.gz: 7b45ade5c1572eb9b60ec5bc96b90cf307ddd470
5
5
  SHA512:
6
- metadata.gz: 9a60726582ea96b9c18f1ffd0dac8930b54c970c1ba31c8f21e7ab52f8bdbc2fdf88b46cd3481b208abe62f5977520680604d13df5caca1568b79b519e8896e6
7
- data.tar.gz: 70f4af33cc151ca020f80a95520914540f51c66bad7ff2c8dc06963cacda3aa34c2208a0fe88545d4206d5b6408aa69a4ab7c6f4c7ac1a39d58416d09702402b
6
+ metadata.gz: 9d3471ace631b643c589efca9461e4810a5db0b5f4a4f0126b56cd033c802d75a3cfb5b44771738869582bf651103679e4bfa7b3628328c5493f9992490bf627
7
+ data.tar.gz: 8e5a1949954982acc175e6bc1f6c3e15070245d5d2643c292ac47fdc56b9cd19a37ac7390ee97c3570dd4269d4b4ae886ee8b35fcdcfc29056b4840bb1ae225b
@@ -1,4 +1,4 @@
1
- === NEXT / 2014-02-10
1
+ === 6.0.0 / 2014-11-25
2
2
 
3
3
  * Enhancements
4
4
 
@@ -120,10 +120,10 @@ Aggregate functions `AVG`, `SUM`, `COUNT`, `MIN`, `MAX`, `HAVING`:
120
120
 
121
121
  ```ruby
122
122
  photos.group(photos[:user_id]).having(photos[:id].count.gt(5)) # => SELECT FROM photos GROUP BY photos.user_id HAVING COUNT(photos.id) > 5
123
- users.project(users[:age].sum) # => SELECT SUM(users.age) AS sum_id FROM users
124
- users.project(users[:age].average) # => SELECT AVG(users.age) AS avg_id FROM users
125
- users.project(users[:age].maximum) # => SELECT MAX(users.age) AS max_id FROM users
126
- users.project(users[:age].minimum) # => SELECT MIN(users.age) AS min_id FROM users
123
+ users.project(users[:age].sum) # => SELECT SUM(users.age) FROM users
124
+ users.project(users[:age].average) # => SELECT AVG(users.age) FROM users
125
+ users.project(users[:age].maximum) # => SELECT MAX(users.age) FROM users
126
+ users.project(users[:age].minimum) # => SELECT MIN(users.age) FROM users
127
127
  users.project(users[:age].count) # => SELECT COUNT(users.age) FROM users
128
128
  ```
129
129
 
@@ -201,7 +201,7 @@ users.
201
201
  project(users[:id], cte_table[:click].sum).
202
202
  with(composed_cte)
203
203
 
204
- # => WITH cte_table AS (SELECT FROM photos WHERE photos.created_at > '2014-05-02') SELECT users.id, SUM(cte_table.click) AS sum_id FROM users INNER JOIN cte_table ON users.id = cte_table.user_id
204
+ # => WITH cte_table AS (SELECT FROM photos WHERE photos.created_at > '2014-05-02') SELECT users.id, SUM(cte_table.click) FROM users INNER JOIN cte_table ON users.id = cte_table.user_id
205
205
  ```
206
206
 
207
207
  When your query is too complex for `Arel`, you can use `Arel::SqlLiteral`:
@@ -21,7 +21,7 @@ require 'arel/delete_manager'
21
21
  require 'arel/nodes'
22
22
 
23
23
  module Arel
24
- VERSION = '6.0.0.beta2'
24
+ VERSION = '6.0.0'
25
25
 
26
26
  def self.sql raw_sql
27
27
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -5,8 +5,14 @@ require 'arel/collectors/plain_string'
5
5
  module Arel
6
6
  module Collectors
7
7
  class SQLString < PlainString
8
+ def initialize(*)
9
+ super
10
+ @bind_index = 1
11
+ end
12
+
8
13
  def add_bind bind
9
- self << bind.to_s
14
+ self << yield(@bind_index)
15
+ @bind_index += 1
10
16
  self
11
17
  end
12
18
 
@@ -5,23 +5,24 @@ module Arel
5
5
  end
6
6
 
7
7
  def sum
8
- Nodes::Sum.new [self], Nodes::SqlLiteral.new('sum_id')
8
+ Nodes::Sum.new [self]
9
9
  end
10
10
 
11
11
  def maximum
12
- Nodes::Max.new [self], Nodes::SqlLiteral.new('max_id')
12
+ Nodes::Max.new [self]
13
13
  end
14
14
 
15
15
  def minimum
16
- Nodes::Min.new [self], Nodes::SqlLiteral.new('min_id')
16
+ Nodes::Min.new [self]
17
17
  end
18
18
 
19
19
  def average
20
- Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id')
20
+ Nodes::Avg.new [self]
21
21
  end
22
22
 
23
23
  def extract field
24
24
  Nodes::Extract.new [self], field
25
25
  end
26
+
26
27
  end
27
28
  end
@@ -4,6 +4,7 @@ require 'arel/nodes/select_statement'
4
4
  require 'arel/nodes/select_core'
5
5
  require 'arel/nodes/insert_statement'
6
6
  require 'arel/nodes/update_statement'
7
+ require 'arel/nodes/bind_param'
7
8
 
8
9
  # terminal
9
10
 
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class BindParam < Node
4
+ end
5
+ end
6
+ end
@@ -10,8 +10,5 @@ module Arel
10
10
  coder.scalar = self.to_s
11
11
  end
12
12
  end
13
-
14
- class BindParam < SqlLiteral
15
- end
16
13
  end
17
14
  end
@@ -55,7 +55,7 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
55
55
  eowarn
56
56
  end
57
57
  between(other)
58
- when Array
58
+ when Enumerable
59
59
  Nodes::In.new self, quoted_array(other)
60
60
  else
61
61
  Nodes::In.new self, quoted_node(other)
@@ -103,7 +103,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
103
103
  eowarn
104
104
  end
105
105
  not_between(other)
106
- when Array
106
+ when Enumerable
107
107
  Nodes::NotIn.new self, quoted_array(other)
108
108
  else
109
109
  Nodes::NotIn.new self, quoted_node(other)
@@ -173,6 +173,12 @@ module Arel
173
173
  def visit_Hash o
174
174
  o.each { |k,v| visit(k); visit(v) }
175
175
  end
176
+
177
+ DISPATCH = dispatch_cache
178
+
179
+ def get_dispatch_cache
180
+ DISPATCH
181
+ end
176
182
  end
177
183
  end
178
184
  end
@@ -132,6 +132,10 @@ module Arel
132
132
  array
133
133
  end
134
134
 
135
+ def visit_Arel_Nodes_BindParam o, collector
136
+ collector.add_bind(o) { |i| ":a#{i}" }
137
+ end
138
+
135
139
  end
136
140
  end
137
141
  end
@@ -23,6 +23,10 @@ module Arel
23
23
  collector << "DISTINCT ON ( "
24
24
  visit(o.expr, collector) << " )"
25
25
  end
26
+
27
+ def visit_Arel_Nodes_BindParam o, collector
28
+ collector.add_bind(o) { |i| "$#{i}" }
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -10,14 +10,14 @@ module Arel
10
10
  private
11
11
 
12
12
  def visit object, collector
13
- send dispatch[object.class.name], object, collector
13
+ send dispatch[object.class], object, collector
14
14
  rescue NoMethodError => e
15
- raise e if respond_to?(dispatch[object.class.name], true)
15
+ raise e if respond_to?(dispatch[object.class], true)
16
16
  superklass = object.class.ancestors.find { |klass|
17
- respond_to?(dispatch[klass.name], true)
17
+ respond_to?(dispatch[klass], true)
18
18
  }
19
19
  raise(TypeError, "Cannot visit #{object.class}") unless superklass
20
- dispatch[object.class.name] = dispatch[superklass.name]
20
+ dispatch[object.class] = dispatch[superklass]
21
21
  retry
22
22
  end
23
23
  end
@@ -186,7 +186,8 @@ module Arel
186
186
 
187
187
  len = o.expressions.length - 1
188
188
  o.expressions.zip(o.columns).each_with_index { |(value, attr), i|
189
- if Nodes::SqlLiteral === value
189
+ case value
190
+ when Nodes::SqlLiteral, Nodes::BindParam
190
191
  collector = visit value, collector
191
192
  else
192
193
  collector << quote(value, attr && column_for(attr)).to_s
@@ -713,7 +714,7 @@ module Arel
713
714
  def literal o, collector; collector << o.to_s; end
714
715
 
715
716
  def visit_Arel_Nodes_BindParam o, collector
716
- collector.add_bind o
717
+ collector.add_bind(o) { "?" }
717
718
  end
718
719
 
719
720
  alias :visit_Arel_Nodes_SqlLiteral :literal
@@ -2,17 +2,7 @@ module Arel
2
2
  module Visitors
3
3
  class Visitor
4
4
  def initialize
5
- @dispatch = Hash.new do |hash, class_name|
6
- raise if class_name == 'Arel::Nodes::Union'
7
- hash[class_name] = "visit_#{(class_name || '').gsub('::', '_')}"
8
- end
9
-
10
- # pre-populate cache. FIXME: this should be passed in to each
11
- # instance, but we can do that later.
12
- self.class.private_instance_methods.sort.each do |name|
13
- next unless name =~ /^visit_(.*)$/
14
- @dispatch[$1.gsub('_', '::')] = name
15
- end
5
+ @dispatch = get_dispatch_cache
16
6
  end
17
7
 
18
8
  def accept object
@@ -21,19 +11,29 @@ module Arel
21
11
 
22
12
  private
23
13
 
14
+ def self.dispatch_cache
15
+ Hash.new do |hash, klass|
16
+ hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
17
+ end
18
+ end
19
+
20
+ def get_dispatch_cache
21
+ self.class.dispatch_cache
22
+ end
23
+
24
24
  def dispatch
25
25
  @dispatch
26
26
  end
27
27
 
28
28
  def visit object
29
- send dispatch[object.class.name], object
29
+ send dispatch[object.class], object
30
30
  rescue NoMethodError => e
31
- raise e if respond_to?(dispatch[object.class.name], true)
31
+ raise e if respond_to?(dispatch[object.class], true)
32
32
  superklass = object.class.ancestors.find { |klass|
33
- respond_to?(dispatch[klass.name], true)
33
+ respond_to?(dispatch[klass], true)
34
34
  }
35
35
  raise(TypeError, "Cannot visit #{object.class}") unless superklass
36
- dispatch[object.class.name] = dispatch[superklass.name]
36
+ dispatch[object.class] = dispatch[superklass]
37
37
  retry
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.beta2
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -11,36 +11,50 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-10-30 00:00:00.000000000 Z
14
+ date: 2014-11-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: minitest
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ~>
20
+ - - "~>"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.4'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.4'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rdoc
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ~>
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '4.0'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ~>
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: '4.0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: rake
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
44
58
  description: |-
45
59
  Arel Really Exasperates Logicians
46
60
 
@@ -63,14 +77,9 @@ extra_rdoc_files:
63
77
  - MIT-LICENSE.txt
64
78
  - README.markdown
65
79
  files:
66
- - .gitignore
67
- - .travis.yml
68
- - Gemfile
69
80
  - History.txt
70
81
  - MIT-LICENSE.txt
71
82
  - README.markdown
72
- - Rakefile
73
- - arel.gemspec
74
83
  - lib/arel.rb
75
84
  - lib/arel/alias_predication.rb
76
85
  - lib/arel/attributes.rb
@@ -89,6 +98,7 @@ files:
89
98
  - lib/arel/nodes/and.rb
90
99
  - lib/arel/nodes/ascending.rb
91
100
  - lib/arel/nodes/binary.rb
101
+ - lib/arel/nodes/bind_param.rb
92
102
  - lib/arel/nodes/count.rb
93
103
  - lib/arel/nodes/delete_statement.rb
94
104
  - lib/arel/nodes/descending.rb
@@ -145,82 +155,29 @@ files:
145
155
  - lib/arel/visitors/visitor.rb
146
156
  - lib/arel/visitors/where_sql.rb
147
157
  - lib/arel/window_predications.rb
148
- - test/attributes/test_attribute.rb
149
- - test/collectors/test_bind_collector.rb
150
- - test/collectors/test_sql_string.rb
151
- - test/helper.rb
152
- - test/nodes/test_and.rb
153
- - test/nodes/test_as.rb
154
- - test/nodes/test_ascending.rb
155
- - test/nodes/test_bin.rb
156
- - test/nodes/test_binary.rb
157
- - test/nodes/test_count.rb
158
- - test/nodes/test_delete_statement.rb
159
- - test/nodes/test_descending.rb
160
- - test/nodes/test_distinct.rb
161
- - test/nodes/test_equality.rb
162
- - test/nodes/test_extract.rb
163
- - test/nodes/test_false.rb
164
- - test/nodes/test_grouping.rb
165
- - test/nodes/test_infix_operation.rb
166
- - test/nodes/test_insert_statement.rb
167
- - test/nodes/test_named_function.rb
168
- - test/nodes/test_node.rb
169
- - test/nodes/test_not.rb
170
- - test/nodes/test_or.rb
171
- - test/nodes/test_over.rb
172
- - test/nodes/test_select_core.rb
173
- - test/nodes/test_select_statement.rb
174
- - test/nodes/test_sql_literal.rb
175
- - test/nodes/test_sum.rb
176
- - test/nodes/test_table_alias.rb
177
- - test/nodes/test_true.rb
178
- - test/nodes/test_update_statement.rb
179
- - test/nodes/test_window.rb
180
- - test/support/fake_record.rb
181
- - test/test_attributes.rb
182
- - test/test_crud.rb
183
- - test/test_delete_manager.rb
184
- - test/test_factory_methods.rb
185
- - test/test_insert_manager.rb
186
- - test/test_select_manager.rb
187
- - test/test_table.rb
188
- - test/test_update_manager.rb
189
- - test/visitors/test_bind_visitor.rb
190
- - test/visitors/test_depth_first.rb
191
- - test/visitors/test_dispatch_contamination.rb
192
- - test/visitors/test_dot.rb
193
- - test/visitors/test_ibm_db.rb
194
- - test/visitors/test_informix.rb
195
- - test/visitors/test_mssql.rb
196
- - test/visitors/test_mysql.rb
197
- - test/visitors/test_oracle.rb
198
- - test/visitors/test_postgres.rb
199
- - test/visitors/test_sqlite.rb
200
- - test/visitors/test_to_sql.rb
201
158
  homepage: https://github.com/rails/arel
202
159
  licenses:
203
160
  - MIT
204
161
  metadata: {}
205
162
  post_install_message:
206
163
  rdoc_options:
207
- - --main
164
+ - "--main"
208
165
  - README.markdown
209
166
  require_paths:
210
167
  - lib
211
168
  required_ruby_version: !ruby/object:Gem::Requirement
212
169
  requirements:
213
- - - '>='
170
+ - - ">="
214
171
  - !ruby/object:Gem::Version
215
172
  version: '0'
216
173
  required_rubygems_version: !ruby/object:Gem::Requirement
217
174
  requirements:
218
- - - '>'
175
+ - - ">="
219
176
  - !ruby/object:Gem::Version
220
- version: 1.3.1
177
+ version: '0'
221
178
  requirements: []
222
179
  rubyforge_project:
223
- rubygems_version: 2.2.1
180
+ rubygems_version: 2.2.2
224
181
  signing_key:
225
182
  specification_version: 4
226
183
  summary: Arel Really Exasperates Logicians Arel is a SQL AST manager for Ruby