ocean-rails 2.0.8 → 2.1.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: 3bb5b73ec236ad99108aeff9b8f85b9840d68b19
4
- data.tar.gz: 6ba40090f25e11d957d0ccba50a5cdc1d70d8c77
3
+ metadata.gz: ddd77052a13c531215d5a319c731f04a71b52641
4
+ data.tar.gz: 1f6993cbf041b79efe6f58c7dca63fddd0a23ba4
5
5
  SHA512:
6
- metadata.gz: a6060f4e6d31e077f10066e59a73e876f1e3874c88f53cebb6ed972fd2c94b133c99340137c344b5c4b96251020ec6b61ee5522412391f2f6168c930ba89d695
7
- data.tar.gz: b8627857c7f60918750963f1f186962d5d411fd7c317beba1ece0d0330a842d2a56b7559f86c92ca8f4dd75bcf982d9bfcd82a3eafed9b365822fe6b2699f1ff
6
+ metadata.gz: d190b929b801a83006b50a2f97022f97b46241233059c5e2d6e2ff3c398eefd0f894e64a2c4ef353b860665ed1fd2accc4cd19b436837d6ab75304c7b4730cbe
7
+ data.tar.gz: 4c278e2e491ca601d85b5d1100223f80e3012dcb2d4a36c4c68cec5e50ce69bae167a17fbb673b2318d7bcfde2d4dc485239d70e3238b301fe301f0a74159fac
@@ -73,9 +73,9 @@ module ApiResource
73
73
  # Pagination
74
74
  if page.present?
75
75
  page = page.to_i
76
- page_size = page_size.to_i
77
76
  return query.none if page < 0
78
- query = query.limit(page_size || collection_page_size).offset(page_size * page)
77
+ page_size = page_size.to_i || collection_page_size
78
+ query = query.limit(page_size).offset(page_size * page)
79
79
  end
80
80
  # Finally, return the accumulated Relation
81
81
  query
@@ -176,12 +176,25 @@ module OceanApplicationController
176
176
  else
177
177
  resources = x.dup.collect { |m| render_to_string(partial: m.to_partial_path,
178
178
  locals: {m.class.model_name.i18n_key => m}) }
179
- attrs = {count: resources.count,
180
- total_count: x.unscope(:limit, :offset).count
179
+ count = resources.count
180
+ total_count = x.unscope(:limit, :offset).count
181
+ attrs = {count: count,
182
+ total_count: total_count
181
183
  }
182
184
  links = {}
183
185
  if href
184
186
  links['self'] = {href: href, type: 'application/json'}
187
+ if params[:page]
188
+ page = params[:page].to_i
189
+ page_size = params[:page_size].to_i || x.collection_page_size
190
+ last_page = (total_count / page_size).ceil
191
+ prev_page = page > 0 && page - 1
192
+ next_page = page != last_page && page + 1
193
+ links['first_page'] = {href: url_for(params.merge(page: 0)), type: 'application/json'}
194
+ links['last_page'] = {href: url_for(params.merge(page: last_page)), type: 'application/json'}
195
+ links['previous_page'] = {href: url_for(params.merge(page: prev_page)), type: 'application/json'} if prev_page
196
+ links['next_page'] = {href: url_for(params.merge(page: next_page)), type: 'application/json'} if next_page
197
+ end
185
198
  end
186
199
  if links
187
200
  attrs['_links'] = links
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "2.0.8"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday