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 +4 -4
- data/README.md +17 -0
- data/lib/api_me.rb +5 -1
- data/lib/api_me/sorting.rb +0 -1
- data/lib/api_me/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eaa0bc3aa1012e62785ab01d14d6cfd43c213aa
|
4
|
+
data.tar.gz: 8a5b6712ee27defbf5d2c45763bf19b5c57e381f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
data/lib/api_me/sorting.rb
CHANGED
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.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-
|
12
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|