api_me 0.6.0 → 0.7.0

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: 4e8bb2cb3b9c132ede191b0d7276d7cbeabf7252
4
- data.tar.gz: 130bf19a960566c5dc4c5f6ab05cb78c387596ed
3
+ metadata.gz: 7eaa0bc3aa1012e62785ab01d14d6cfd43c213aa
4
+ data.tar.gz: 8a5b6712ee27defbf5d2c45763bf19b5c57e381f
5
5
  SHA512:
6
- metadata.gz: a52cc62640bb368b1e661fcdacb0c43f87fc93f99e5d87acaa421ad6fa90287f95326521255e4a5d442f7b5f111f4b0da4f920123d4d822e23b172fdafd627db
7
- data.tar.gz: 77004d9ae0c8728fa094744ad96fb2c37dbb9b2318ba41ab7c37f35d08daddd9111aeb77438296d9050c14aa7d1b6509b10fe1751027def01690821e82661fcd
6
+ metadata.gz: e1a4bbc4b1dd7278b18c96f8e307f74395e4a2d678f27e0108c7d8f4bb886d26983e70b3539cfe620c370962b1be149040065c8505f364f7880d22705070890a
7
+ data.tar.gz: dd6b5886ed746e190ec31b3c3ada9dac8761d6dedf5e92cd464f6ab336e769e521791a1778060f7b4a65e165771b369bccfad67d5749b252c9e987c6ffd93923
data/README.md CHANGED
@@ -83,6 +83,23 @@ end
83
83
  ````
84
84
  The ApiMe::BaseFilter is called if no filter exists for the resource, by default the base filter provides filtering by ids for convenience. I.E a GET to `/api/v1/users?ids%5B%5D=1&ids%5B%5D=3` would return users filtered by ids of 1 and 3. All other filters are expected by default to be located at `params[:filters]` and not at the base level.
85
85
 
86
+ ### Sorting
87
+
88
+ To enable sorting just pass `sort` in your request with `sortCiteria` and `sortReverse`.
89
+
90
+ Ember Example
91
+ ````js
92
+ return this.store.query('some-model', {
93
+ filters: {
94
+ cool_models_only: true
95
+ },
96
+ sort: {
97
+ criteria: 'createdAt', // Property to sort on.
98
+ reverse: false, // True reverses the sort.
99
+ }
100
+ });
101
+ ````
102
+
86
103
  ### Overrides
87
104
  Overriding the default model class, serializer class, filter class, and filter parameter can be done like so:
88
105
 
data/lib/api_me.rb CHANGED
@@ -68,7 +68,7 @@ module ApiMe
68
68
  def index
69
69
  @policy_scope = policy_scope(resource_scope)
70
70
  @filter_scope = filter_scope(@policy_scope)
71
- @sorted_scope = ApiMe::Sorting.new(scope: @filter_scope, sort_params: params[:sort]).results
71
+ @sorted_scope = sort_scope(@filter_scope, params[:sort])
72
72
  @pagination_object = ApiMe::Pagination.new(scope: @sorted_scope, page_params: params[:page])
73
73
 
74
74
  render json: @pagination_object.results, each_serializer: serializer_klass, meta: { page: @pagination_object.page_meta }
@@ -157,6 +157,10 @@ module ApiMe
157
157
  ).results
158
158
  end
159
159
 
160
+ def sort_scope(scope, params)
161
+ ApiMe::Sorting.new(scope: scope, sort_params: params).results
162
+ end
163
+
160
164
  def params_klass_symbol
161
165
  model_klass.name.demodulize.underscore.to_sym
162
166
  end
@@ -4,7 +4,6 @@ module ApiMe
4
4
 
5
5
  def initialize(scope:, sort_params:)
6
6
  self.scope = scope
7
-
8
7
  if sort_params
9
8
  self.sort_criteria = sort_params[:criteria]
10
9
  self.sort_reverse = sort_params[:reverse]
@@ -1,3 +1,3 @@
1
1
  module ApiMe
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  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.6.0
4
+ version: 0.7.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: 2016-05-27 00:00:00.000000000 Z
12
+ date: 2016-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord