api_me 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -0
- data/lib/api_me.rb +16 -1
- data/lib/api_me/sorting.rb +2 -4
- data/lib/api_me/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6657f0351e5c79bfb0c927436fcd4f9f26be8cc93e384429a1e3bd8e18bea1c
|
4
|
+
data.tar.gz: ba9d1e17654d46b38f6b35c5a3aa1e3f9bb2a73211ed7f4043840090f901cfe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d889833b28bea829737d3c19f1faf670df9170b7ad5dcb9c39d4cf0c3a44c21ecc3654b975776cac9dcfda22296b96e6d5d7c0edccd7ba4b4ec9afdf68807c35
|
7
|
+
data.tar.gz: e59cd90e4ffbe7aa7ebdc5b31c947278f5bd8ce1d360cd0a54c46cdf14d058342fe619a755dd05bde96eb833461d6bfeb7933ed59e2bd2d691ced19268b3f3e8
|
data/Rakefile
CHANGED
@@ -19,3 +19,10 @@ load 'rails/tasks/engine.rake'
|
|
19
19
|
load 'rails/tasks/statistics.rake'
|
20
20
|
|
21
21
|
Bundler::GemHelper.install_tasks
|
22
|
+
require "rake"
|
23
|
+
require "rspec/core/rake_task"
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
25
|
+
t.pattern = Dir.glob("spec/**/*_spec.rb")
|
26
|
+
t.rspec_opts = "--format documentation"
|
27
|
+
end
|
28
|
+
task default: :spec
|
data/lib/api_me.rb
CHANGED
@@ -73,7 +73,15 @@ module ApiMe
|
|
73
73
|
@sorted_scope = sort_scope(@filter_scope)
|
74
74
|
@pagination_object = paginate_scope(@sorted_scope, page_params)
|
75
75
|
|
76
|
-
render
|
76
|
+
render({
|
77
|
+
json: @pagination_object.results,
|
78
|
+
root: collection_root_key,
|
79
|
+
each_serializer: serializer_klass,
|
80
|
+
meta: {
|
81
|
+
page: @pagination_object.page_meta,
|
82
|
+
sort: sorting_meta(@filter_scope)
|
83
|
+
}
|
84
|
+
})
|
77
85
|
end
|
78
86
|
|
79
87
|
def show
|
@@ -194,6 +202,13 @@ module ApiMe
|
|
194
202
|
).results
|
195
203
|
end
|
196
204
|
|
205
|
+
def sorting_meta(scope, sortable_params = sort_params)
|
206
|
+
sort_klass.new(
|
207
|
+
scope: scope,
|
208
|
+
sort_params: sortable_params
|
209
|
+
).sort_meta
|
210
|
+
end
|
211
|
+
|
197
212
|
def sort_scope(scope, sortable_params = sort_params)
|
198
213
|
sort_klass.new(
|
199
214
|
scope: scope,
|
data/lib/api_me/sorting.rb
CHANGED
@@ -8,7 +8,7 @@ module ApiMe
|
|
8
8
|
self.scope = scope
|
9
9
|
return unless sort_params
|
10
10
|
self.sort_criteria = sort_params[:criteria] || default_sort_criteria
|
11
|
-
self.sort_reverse = sort_params[:reverse]
|
11
|
+
self.sort_reverse = sort_params[:reverse] || false
|
12
12
|
end
|
13
13
|
|
14
14
|
def results
|
@@ -19,9 +19,7 @@ module ApiMe
|
|
19
19
|
return {} unless sorting?
|
20
20
|
{
|
21
21
|
criteria: sort_meta_criteria,
|
22
|
-
reverse: sort_reverse
|
23
|
-
record_count: scope.size,
|
24
|
-
total_records: scope.total_count
|
22
|
+
reverse: sort_reverse
|
25
23
|
}
|
26
24
|
end
|
27
25
|
|
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.10.
|
4
|
+
version: 0.10.2
|
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: 2018-11
|
12
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|