directiverecord 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +4 -0
- data/VERSION +1 -1
- data/lib/directive_record/query/sql.rb +22 -3
- data/lib/directive_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2I3ZDI1Yzk0OWViMDIxYjFlMGU2ZjM5NjVhMDY4MzI1NDQ0ZGViZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjRkYzVkODQwNDNjYzc4ZDZmYWNlNDJhNDMyMjM5ZjhiYTVmZGVkOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzM2ODg4NTBjZDc4YmQ5MjExYWZiYzA2MDZhY2U5ZTY0Njg2YzAzM2YyZWFl
|
10
|
+
ZjFmNjEyM2FiZTczOTBkMjEwZmRkMTU3NTIwNDUxYzhkMDY5YWQ1NDgyNWY3
|
11
|
+
N2EzZWY0YWI0ODM1YWEwNzJlNzgwNzU5MTNhZWEzY2RlMmY2YWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGNmNzZlMDRiNGIxZDcyNDZkYTMxNmFlZTQxYzZhNzMyZWRhYjhmMGY4OGIx
|
14
|
+
Y2ZiYmQ5N2NmYmU3N2UzMmRhMWZhN2VkNWQ5NjYyZTMwZjY2ZGY5MDI5YTRk
|
15
|
+
NzNjMTBkMWRmNzhmNmQwNDhkOTQ0NTYzZmJlYTU5ODBmNzkwZDg=
|
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.18
|
@@ -10,7 +10,9 @@ module DirectiveRecord
|
|
10
10
|
options = to_options(args)
|
11
11
|
validate_options! options
|
12
12
|
|
13
|
-
original_options = options.deep_dup
|
13
|
+
original_options = options.deep_dup
|
14
|
+
original_options.reject!{|k, v| v.nil?}
|
15
|
+
|
14
16
|
check_path_delimiter! options
|
15
17
|
optimize_query! options
|
16
18
|
|
@@ -168,13 +170,14 @@ SQL
|
|
168
170
|
|
169
171
|
def normalize_subselect!(options, original_options)
|
170
172
|
options[:subselect] = options[:subselect].sort_by{|name, (klass, opts)| opts[:join] ? 0 : 1}.collect do |name, (klass, opts)|
|
171
|
-
qry_options = original_options.deep_dup
|
173
|
+
qry_options = original_options.deep_dup
|
174
|
+
qry_options.reject!{|k, v| [:subselect, :numerize_aliases, :limit, :offset, :order_by, :join, :flatten].include?(k)}
|
172
175
|
|
173
176
|
opts.each do |key, value|
|
174
177
|
value = [value].flatten
|
175
178
|
if key == :select
|
176
179
|
qry_options[key] = value
|
177
|
-
elsif
|
180
|
+
elsif [:join, :flatten].include?(key)
|
178
181
|
# do nothing
|
179
182
|
elsif key.to_s.match(/include_(\w+)/)
|
180
183
|
(qry_options[$1.to_sym] || []).select!{|x| value.any?{|y| x.include?(y)}}
|
@@ -203,6 +206,22 @@ SQL
|
|
203
206
|
end
|
204
207
|
|
205
208
|
query = klass.to_qry(qry_options).gsub(/\n\s*/, " ").gsub(/#{base_alias}[\s\.]/, "")
|
209
|
+
|
210
|
+
if opts[:flatten]
|
211
|
+
qry_alias = quote_alias("_#{name}")
|
212
|
+
|
213
|
+
dup_options = qry_options.deep_dup
|
214
|
+
normalize_select!(dup_options)
|
215
|
+
prepend_base_alias!(dup_options)
|
216
|
+
|
217
|
+
select = dup_options[:select].collect do |sql|
|
218
|
+
sql_alias = sql.match(/ AS (.*?)$/).captures[0]
|
219
|
+
"SUM(#{qry_alias}.#{sql_alias}) AS #{sql_alias}"
|
220
|
+
end
|
221
|
+
|
222
|
+
query = "SELECT #{select.join(", ")} FROM (#{query}) #{qry_alias}"
|
223
|
+
end
|
224
|
+
|
206
225
|
"#{prefix}(#{query}) #{query_alias}#{postfix}"
|
207
226
|
|
208
227
|
end if options[:subselect]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directiverecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|