smql 0.0.5.2 → 0.0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/smql_to_ar/query_builder.rb +10 -7
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5.2
1
+ 0.0.5.3
@@ -248,12 +248,14 @@ class SmqlToAR
248
248
  def optimize!
249
249
  ext = []
250
250
  collect! do |sub|
251
- sub = sub.optimize! if sub.kind_of? Array
251
+ sub = sub.optimize! if sub.kind_of? SubBuilder
252
252
  if self.class == sub.class
253
253
  ext.push *sub
254
254
  nil
255
255
  elsif sub.blank?
256
256
  nil
257
+ elsif 1 == sub.size
258
+ sub.first
257
259
  else
258
260
  sub
259
261
  end
@@ -267,21 +269,22 @@ class SmqlToAR
267
269
  end
268
270
  def default() SmqlToAR::And end
269
271
  def default_new( parent) default.new self, parent, false end
270
- def collect_build_where
271
- collect {|x| x.respond_to?( :build_where) ? x.build_where : x.to_s }
272
+ def collect_build_where indent = nil
273
+ indent = (indent||0) + 1
274
+ collect {|x| "(#{x.respond_to?( :build_where) ? x.build_where( indent) : x.to_s})" }
272
275
  end
273
276
  end
274
277
 
275
278
  class And < SubBuilder
276
279
  def default; SmqlToAR::Or; end
277
- def build_where
278
- collect_build_where.join ' AND '
280
+ def build_where indent = nil
281
+ collect_build_where( indent).join " AND\n"+"\t"*(indent||0)
279
282
  end
280
283
  end
281
284
 
282
285
  class Or < SubBuilder
283
- def build_where
284
- collect_build_where.join ' OR '
286
+ def build_where indent = nil
287
+ collect_build_where( indent).join " OR\n"+"\t"*(indent||0)
285
288
  end
286
289
  end
287
290
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.0.5.2
9
+ - 3
10
+ version: 0.0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Denis Knauf
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-17 00:00:00 +01:00
18
+ date: 2012-01-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency