api_me 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/api_me.rb +15 -7
  3. data/lib/api_me/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bb083a8ae092dc1b2ddc5eb4315f5205abf99a1
4
- data.tar.gz: 68083ea1ca7e8eb53649ee01fcdee436698bd074
3
+ metadata.gz: e70094d4fd7b9ae7f7cfddc4dbfe9cec2e94d3ef
4
+ data.tar.gz: 698e8957b40252211d1f6ee22ff5fa05ab19cb79
5
5
  SHA512:
6
- metadata.gz: 7582d107d7106384ade98f43b4dc29c4195dc4fd9ac8a52c90b67bec936e3a1aecaef8199179a5d4c60f48d6c1c7157e68bcd0fd40e0b03a888158cf04c345f4
7
- data.tar.gz: 2364f5da072045c31e308f3b3f3bb516fe51a1266d3d7b0f7305e3f352675bc52a7a05b12309adc1863a31d5b6609c481c12d3e9f92d43ba3da07062234b1e6c
6
+ metadata.gz: b75592dd259a25e71a5ed7af2ff43be82aa51afb939c79ced4f249b76da2954c8c0bfd5ae4881cf748984ce50760935e5294a4f8466a9a143752e491057273b2
7
+ data.tar.gz: e04298b570816de02a33a062241f234b0da3421d89bf6bad9668fd04bd083b5285c53c538c52ea3cadc4f8bb60d218388dfdd6c5ae7bc47f94ade02be659de07
data/lib/api_me.rb CHANGED
@@ -65,13 +65,9 @@ module ApiMe
65
65
  # the top level ids array param. Would eventually like
66
66
  # to move to support the jsonapi.org standard closer.
67
67
  def index
68
- ids_filter_hash = params[:ids] ? { ids: params[:ids] } : {}
69
- @scoped_objects = policy_scope(resource_scope)
70
- @filter_object = filter_klass.new(
71
- scope: @scoped_objects,
72
- filters: (filter_params || {}).merge(ids_filter_hash)
73
- )
74
- @pagination_object = ApiMe::Pagination.new(scope: @filter_object.results, page_params: params[:page])
68
+ @policy_scope = policy_scope(resource_scope)
69
+ @filter_scope = filter_scope(@policy_scope)
70
+ @pagination_object = ApiMe::Pagination.new(scope: @filter_scope, page_params: params[:page])
75
71
 
76
72
  render json: @pagination_object.results, each_serializer: serializer_klass, meta: { page: @pagination_object.page_meta }
77
73
  end
@@ -151,10 +147,22 @@ module ApiMe
151
147
  def resource_scope
152
148
  model_klass.all
153
149
  end
150
+
151
+ def filter_scope(scope)
152
+ filter_klass.new(
153
+ scope: scope,
154
+ filters: filters_hash
155
+ ).results
156
+ end
154
157
 
155
158
  def params_klass_symbol
156
159
  model_klass.name.demodulize.underscore.to_sym
157
160
  end
161
+
162
+ def filters_hash
163
+ ids_filter_hash = params[:ids] ? { ids: params[:ids] } : {}
164
+ (filter_params || {}).merge(ids_filter_hash)
165
+ end
158
166
 
159
167
  def filter_params
160
168
  params[:filters]
@@ -1,3 +1,3 @@
1
1
  module ApiMe
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
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.5.2
4
+ version: 0.5.3
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-03 00:00:00.000000000 Z
12
+ date: 2016-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord