directiverecord 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ca244266a160abe5e8397beb0e9cb92def53a747
4
- data.tar.gz: b419b9776bdb3aeda8cfed589f8ceca8662b91b9
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTRiYmVkOTVmOWQwNjg0NGNlYjllYjdkZWFmNDI2ZjU0N2FkYjE4ZA==
5
+ data.tar.gz: !binary |-
6
+ NmU5MWY1NzM2OTI1ZTM4ZWIwNjEzZjJhNTg0YzJmMjc1ODJhMDAwNQ==
5
7
  SHA512:
6
- metadata.gz: 96eff97742fac7acc0f37a93c86322eae178753425ecfc0172ea690a2af9fccb107a9a8c8c205af04c09a8389083abadd8ebc72ca50ed109d21dd2b65e688056
7
- data.tar.gz: 931f0ccd6eba753d5bb70b223571b9d99c89a4e33bda225cb9a34d07372acf7b8b755bf7828742f86792da342977394479eb9cf137ffe7045a3a3b993d64a66b
8
+ metadata.gz: !binary |-
9
+ ZjdlZWY4NDg0NTRmMTRiYjViNWY5M2E4NTZkMWNkYjFiNmJkYTY2ZTU2YWNj
10
+ YjZlZDkzY2NhYzE4NTM5NDU1MjY3ZmNkZjBkNGE2NGIyN2M4YjJhM2M0Mjdk
11
+ YzYwZjRhZDc0NDQyMWZjNDdkOTBhYzY5MGM1YWFmMGM5YzAzOTA=
12
+ data.tar.gz: !binary |-
13
+ YTI5NjE0NGJiMGVlNzVmZGM5OThkODQwMGNlOTE1NGJhNWQxZTNlMDU1NzQ1
14
+ YmUzMzQxMjBmN2NiZDczZTE3ZjQ3ZjA5ZDQ1OGM1MzU0MDc4ZWUwNmEwN2U5
15
+ MzMxMjJhZDQ0MjEwNjFkYjEwMzczYWRhYzZhNjY0ZDNkZWY4ZmQ=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.15 (March 10, 2015)
4
+
5
+ * Being able to include / exclude subselect options
6
+ * Being able to join with a subselect
7
+ * Also auto-applying aggregate method for paths within conditions
8
+
3
9
  == Version 0.1.14 (March 9, 2015)
4
10
 
5
11
  * Corrected normalize_select!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.14
1
+ 0.1.15
@@ -167,24 +167,41 @@ SQL
167
167
  end
168
168
 
169
169
  def normalize_subselect!(options, original_options)
170
- options[:subselect] = options[:subselect].collect do |name, (klass, opts)|
171
- qry_options = original_options.deep_dup.reject!{|k, v| [:subselect, :numerize_aliases, :limit, :offset, :group_by, :order_by].include?(k)}
170
+ 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.reject!{|k, v| [:subselect, :numerize_aliases, :limit, :offset, :order_by].include?(k)}
172
172
 
173
173
  opts.each do |key, value|
174
174
  value = [value].flatten
175
175
  if key == :select
176
176
  qry_options[key] = value
177
- elsif key.to_s.match(/ignore_(\w+)/)
178
- qry_options[$1.to_sym].reject!{|x| value.any?{|y| x.include?(y)}}
177
+ elsif key == :join
178
+ # do nothing
179
+ elsif key.to_s.match(/include_(\w+)/)
180
+ (qry_options[$1.to_sym] || []).select!{|x| value.any?{|y| x.include?(y)}}
181
+ elsif key.to_s.match(/exclude_(\w+)/)
182
+ (qry_options[$1.to_sym] || []).reject!{|x| value.any?{|y| x.include?(y)}}
179
183
  else
180
184
  qry_options[key].concat value
181
185
  end
182
186
  end
183
187
 
184
188
  base_alias = quote_alias(klass.table_name.split("_").collect{|x| x[0]}.join(""))
185
- query = klass.to_qry(qry_options).gsub("\n", " ").gsub(/#{base_alias}[\s\.]/, "")
189
+ query_alias = quote_alias(name)
190
+
191
+ if opts[:join] && !qry_options[:group_by].blank?
192
+ joins = qry_options[:group_by].collect do |path|
193
+ qry_options[:select].unshift(column = path.gsub(/\.\w+$/, "_id").strip)
194
+ "#{query_alias}.#{column} = #{base_alias}.#{column}"
195
+ end
196
+ prefix = "LEFT JOIN\n "
197
+ postfix = " ON #{joins.join(" AND ")}"
198
+ else
199
+ prefix = " , "
200
+ end
201
+
202
+ query = klass.to_qry(qry_options).gsub(/\n\s*/, " ").gsub(/#{base_alias}[\s\.]/, "")
203
+ "#{prefix}(#{query}) #{query_alias}#{postfix}"
186
204
 
187
- " , (#{query}) #{quote_alias(name)}"
188
205
  end if options[:subselect]
189
206
  end
190
207
 
@@ -196,12 +213,13 @@ SQL
196
213
  regexp, aliases = /^\S+/, options[:aliases].invert
197
214
 
198
215
  where, having = (options[:where] || []).partition do |statement|
216
+ !options[:aggregated].keys.include?(statement.strip.match(regexp).to_s) &&
199
217
  statement.gsub(/((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)\1/, " ")
200
218
  .split(/\b(and|or)\b/i).reject{|sql| %w(and or).include? sql.downcase}
201
219
  .collect{|sql| sql = sql.strip; (sql[0] == "(" && sql[-1] == ")" ? sql[1..-1] : sql)}
202
220
  .all? do |sql|
203
221
  sql.match /(.*)\s*(=|<=>|>=|>|<=|<|<>|!=|is|like|rlike|regexp|in|between|not|sounds|soundex)(\b|\s|$)/i
204
- path = $1.strip rescue binding.pry
222
+ path = $1.strip
205
223
  !(aliases[path] || path).match(/\b(count|sum|min|max|avg)\(/i)
206
224
  end
207
225
  end
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 14
4
+ TINY = 15
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directiverecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
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-09 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: arel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "<"
31
+ - - <
32
32
  - !ruby/object:Gem::Version
33
33
  version: 6.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "<"
38
+ - - <
39
39
  - !ruby/object:Gem::Version
40
40
  version: 6.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mysql2
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: mocha
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - ! '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: A layer on top of ActiveRecord for using paths within queries without
@@ -143,7 +143,7 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".gitignore"
146
+ - .gitignore
147
147
  - CHANGELOG.rdoc
148
148
  - Gemfile
149
149
  - MIT-LICENSE
@@ -195,17 +195,17 @@ require_paths:
195
195
  - lib
196
196
  required_ruby_version: !ruby/object:Gem::Requirement
197
197
  requirements:
198
- - - ">="
198
+ - - ! '>='
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
- - - ">="
203
+ - - ! '>='
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 2.2.2
208
+ rubygems_version: 2.1.11
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: A layer on top of ActiveRecord for using paths within queries without thinking