incline 0.2.25 → 0.2.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33433684e0ddf6d5ea692b73352df41cf6515f0c
4
- data.tar.gz: 8d5c29273d9ca46fdd18facdca7585621543541d
3
+ metadata.gz: f450825492e9998e61730273f23eece45027fa0a
4
+ data.tar.gz: 65c8d04ee7f53deed946071c433c4c4dd00a3637
5
5
  SHA512:
6
- metadata.gz: cddbe4ec1264f5d36ce6d4bb5e93e90d8b7a3cab3aad95b10e292874ed991196b6e8f5c4fe7d88c411e11e9256191870e6bcdadf536e2f20f7896b4bbede8dcc
7
- data.tar.gz: 2c7f96f42acc17a18227478ce2099903f2f35c137ab700e8caa38b7595502a41b5d6a3912b4c63a7c9ed6c44dea04a3f71286fc99653e9bb137fa30018e4f928
6
+ metadata.gz: 00c007bdc0c21cc51f28d0eb267ade695f70f8e29a70eaf8cde1e33ccea72fd14e8d0add429b1e568fa52df7f034a4b012c4d863aa0f6b5c594c814fc3fdd139
7
+ data.tar.gz: e8989b1486b14dcc7edb05ce44cafbc5bf98e96b20cbb9e56e5a70ef53d573118f75b7949108f089c6f6814c27c09d06bb98c8cb075ea204d60ed120a0a62ad5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incline (0.2.25)
4
+ incline (0.2.26)
5
5
  ansi (~> 1.5.0)
6
6
  bcrypt
7
7
  bootstrap-sass
@@ -260,7 +260,10 @@ module Incline
260
260
  columns.reject {|c| !c[:searchable] || relation.model.column_names.include?(c[:name].to_s) }.any?
261
261
  )
262
262
 
263
- Incline::Log::debug "Filtering will be done #{filter_local ? 'application' : 'database'}-side."
263
+ order_local = ordering.blank? || ordering.reject{|k,_| relation.model.column_names.include?(k.to_s)}.any?
264
+
265
+ Incline::Log::debug "Filtering will be done #{(filter_local || order_local) ? 'application' : 'database'}-side."
266
+ Incline::Log::debug "Ordering will be done #{order_local ? 'application' : 'database'}-side."
264
267
 
265
268
  unless filter_local
266
269
  ### Database Side Individual Filtering (AND) ###
@@ -282,19 +285,23 @@ module Incline
282
285
  end
283
286
 
284
287
  ### Database Side Ordering ###
285
- if ordering.blank?
286
- relation = relation.order(id: :asc)
287
- else
288
+ unless order_local
288
289
  relation = relation.order(ordering)
289
290
  end
290
291
 
291
- # Now we have two paths, if we are filtering locally, we need to return everything up to this point and
292
+ # Now we have two paths, if we are filtering/ordering locally, we need to return everything up to this point and
292
293
  # perform our filters before limiting the results.
293
- # If we filtered at the database, then we can limit the results there as well.
294
- if filter_local
294
+ # If we filtered and ordered at the database, then we can limit the results there as well.
295
+ if filter_local || order_local
295
296
  # execute the query
296
297
  relation = relation.to_a
297
298
 
299
+ ### Application Side Ordering ###
300
+ if order_local
301
+ ordering_list = ordering.to_a
302
+ relation.sort{|a,b| local_sort(a, b, ordering_list) }
303
+ end
304
+
298
305
  ### Local Individual Filtering (AND) ###
299
306
  columns.reject{|c| c[:search].blank? || c[:name].blank?}.each do |col|
300
307
  name = col[:name].to_s
@@ -351,5 +358,26 @@ module Incline
351
358
  end
352
359
  end
353
360
 
361
+ private
362
+
363
+ def local_sort(a, b, attribs, index = 0)
364
+ if index >= attribs.count
365
+ 0
366
+ else
367
+ attr, dir = attribs[index]
368
+ val_a = a.send(attr)
369
+ val_b = b.send(attr)
370
+ if val_a == val_b
371
+ local_sort a, b, attribs, index + 1
372
+ else
373
+ if dir.to_s.downcase == 'desc'
374
+ val_b <=> val_a
375
+ else
376
+ val_a <=> val_b
377
+ end
378
+ end
379
+ end
380
+ end
381
+
354
382
  end
355
383
  end
@@ -1,3 +1,3 @@
1
1
  module Incline
2
- VERSION = "0.2.25"
2
+ VERSION = "0.2.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.25
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -610,7 +610,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
610
610
  version: '0'
611
611
  requirements: []
612
612
  rubyforge_project:
613
- rubygems_version: 2.5.2
613
+ rubygems_version: 2.6.11
614
614
  signing_key:
615
615
  specification_version: 4
616
616
  summary: A gem designed to get off to an even quicker start with Rails.