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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39a270d1add657789129c44d5e606184e03deb03531915f101edd16eec9d9068
4
- data.tar.gz: b87c5f6be41cd40479d686c969be2486fd1c5e6aec0d4a7415276a7283832dca
3
+ metadata.gz: a6657f0351e5c79bfb0c927436fcd4f9f26be8cc93e384429a1e3bd8e18bea1c
4
+ data.tar.gz: ba9d1e17654d46b38f6b35c5a3aa1e3f9bb2a73211ed7f4043840090f901cfe6
5
5
  SHA512:
6
- metadata.gz: 31a4c43ee426d381349deef5661d26bf9cabb8241b8713858ce8e5accde81fbc82c616c0ba330cab3af99c1973c948d4ea79ea6000231de9fc1b0f508531088d
7
- data.tar.gz: bcecd4b651a8e7ff290a6f74e47f04033d04508cff746322e2d98fc239b94081e86eb008812b476dc90d2664fdeb2f073a630c43a7cce9b4d60197294422d98c
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 json: @pagination_object.results, root: collection_root_key, each_serializer: serializer_klass, meta: { page: @pagination_object.page_meta } # rubocop:disable Metrics/LineLength
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,
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiMe
4
- VERSION = '0.10.1'
4
+ VERSION = '0.10.2'
5
5
  end
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.1
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-05 00:00:00.000000000 Z
12
+ date: 2018-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails