api_me 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_me.rb +2 -2
- data/lib/api_me/sorting.rb +17 -3
- data/lib/api_me/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6edbf66319db35e695cd3b4b686e3b5688a2c2fe56d108eb954976732bc11bb5
|
4
|
+
data.tar.gz: 6063c1ca77185b64178360c103f6c3511b6fe9652575ee00da2a99d97d626dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d08b61cc42bcaa27102961bea0b54c651e1fa18adbc7034d69531147076e1acdcd5fd09204c83741880b8b527a6269d0ee2634e339159910dd043a7b8bb664c4
|
7
|
+
data.tar.gz: 7c610c2d85ca5009c265c1456e9c3e21d653a762e933ce8f00d6f245dd2efa57fa480c9feee608a9c52a4ff2299bb3f4ed6fd60b471989fb9071e04ffca37589
|
data/lib/api_me.rb
CHANGED
data/lib/api_me/sorting.rb
CHANGED
@@ -2,13 +2,16 @@
|
|
2
2
|
|
3
3
|
module ApiMe
|
4
4
|
class Sorting
|
5
|
-
attr_accessor :sort_criteria, :sort_reverse, :scope
|
5
|
+
attr_accessor :sort_criteria, :sort_reverse, :scope, :custom_sort_options
|
6
6
|
|
7
|
-
def initialize(scope:, sort_params:)
|
7
|
+
def initialize(scope:, sort_params:, custom_sort_options: {})
|
8
8
|
self.scope = scope
|
9
|
+
|
9
10
|
return unless sort_params
|
11
|
+
|
10
12
|
self.sort_criteria = sort_params[:criteria] || default_sort_criteria
|
11
13
|
self.sort_reverse = sort_params[:reverse] || false
|
14
|
+
self.custom_sort_options = custom_sort_options
|
12
15
|
end
|
13
16
|
|
14
17
|
def results
|
@@ -39,7 +42,14 @@ module ApiMe
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def sorted_scope(criteria)
|
42
|
-
|
45
|
+
criteria_key = criteria.to_sym
|
46
|
+
if custom_sort_options.key?(criteria_key)
|
47
|
+
if sort_reverse == 'true'
|
48
|
+
custom_sort_scope(criteria_key).order(Arel.sql("#{custom_sort_options[criteria_key][:column]} DESC"))
|
49
|
+
else
|
50
|
+
custom_sort_scope(criteria_key).order(Arel.sql("#{custom_sort_options[criteria_key][:column]} ASC"))
|
51
|
+
end
|
52
|
+
elsif sort_reverse == 'true'
|
43
53
|
scope.order(criteria => :desc)
|
44
54
|
else
|
45
55
|
scope.order(criteria => :asc)
|
@@ -48,6 +58,10 @@ module ApiMe
|
|
48
58
|
|
49
59
|
private
|
50
60
|
|
61
|
+
def custom_sort_scope(criteria)
|
62
|
+
custom_sort_options[criteria].key?(:joins) ? scope.joins(custom_sort_options[criteria][:joins]) : scope
|
63
|
+
end
|
64
|
+
|
51
65
|
def default_sort_criteria
|
52
66
|
'id'
|
53
67
|
end
|
data/lib/api_me/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Clopton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.7.6
|
202
|
+
rubygems_version: 2.7.6.2
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Api Me
|