api_helper 0.1.0 → 0.1.1

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: 1895625d870d6629c579f3f165f1f37090dc4d12
4
- data.tar.gz: b1fc9a045cebe92869ff7a4f666b3e813c5c7bb0
3
+ metadata.gz: 9efe86fda7179ba792ecf18057ebf0b1445d7f83
4
+ data.tar.gz: 9f17ca34299833efa46df0e68a1f75d1470d269b
5
5
  SHA512:
6
- metadata.gz: c908f21b13a0f04dc0531cfe8fe97d2fd93182d1c119139caeb56387f6c905e4d516c40668ad5a1f2ba1ff05d580faa389eb1afa12a16774110136ef3b7478ac
7
- data.tar.gz: 8800b5d99bd5e252474bdefb57792e6274eba29819da938c8931dde286e4ecea7a0fcd618c6af44f6f9ca60f658ea7f356fb6d8a38d27a26713491e188b30821
6
+ metadata.gz: fcfd8f2af69946d843ebfd2f0579ef44f8db74b816c9a6843df7fd5cdb95565b8f93a3f5767b195089cec00f5b0a9894f7cf69300c133fb1116da37a43f4118b
7
+ data.tar.gz: eb80f9bd80df82e8ae784b4b4a368c39c47d63ce16a910025d225d3197af26501d3e0e8bfff7be5cfe9ab002d62ba3c022fed09487dd4d1d10ae3671075ee5e6
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.2.0
3
+ - 2.3.0
5
4
  gemfile:
6
5
  - gemfiles/rails_4.1.0.gemfile
7
6
  - gemfiles/rails_4.2.0.gemfile
@@ -94,21 +94,34 @@ module APIHelper::Paginatable
94
94
  pages_count = (items_count.to_f / @pagination_per_page).ceil
95
95
  pages_count = 1 if pages_count < 1
96
96
 
97
+ @pagination_items_count = items_count
98
+ @pagination_pages_count = pages_count
99
+
97
100
  @pagination_page = (params[:page] || 1).to_i
98
101
  @pagination_page = pages_count if @pagination_page > pages_count
99
102
  @pagination_page = 1 if @pagination_page < 1
100
103
 
104
+ if current_page > 1
105
+ @pagination_first_page_url = add_or_replace_uri_param(request.url, :page, 1)
106
+ @pagination_prev_page_url = add_or_replace_uri_param(request.url, :page, (current_page > pages_count ? pages_count : current_page - 1))
107
+ end
108
+
109
+ if current_page < pages_count
110
+ @pagination_next_page_url = add_or_replace_uri_param(request.url, :page, current_page + 1)
111
+ @pagination_last_page_url = add_or_replace_uri_param(request.url, :page, pages_count)
112
+ end
113
+
101
114
  if set_header
102
115
  link_headers ||= []
103
116
 
104
117
  if current_page > 1
105
- link_headers << "<#{add_or_replace_uri_param(request.url, :page, 1)}>; rel=\"first\""
106
- link_headers << "<#{add_or_replace_uri_param(request.url, :page, (current_page > pages_count ? pages_count : current_page - 1))}>; rel=\"prev\""
118
+ link_headers << "<#{@pagination_first_page_url}>; rel=\"first\"" if @pagination_first_page_url
119
+ link_headers << "<#{@pagination_prev_page_url}>; rel=\"prev\"" if @pagination_prev_page_url
107
120
  end
108
121
 
109
122
  if current_page < pages_count
110
- link_headers << "<#{add_or_replace_uri_param(request.url, :page, current_page + 1)}>; rel=\"next\""
111
- link_headers << "<#{add_or_replace_uri_param(request.url, :page, pages_count)}>; rel=\"last\""
123
+ link_headers << "<#{@pagination_next_page_url}>; rel=\"next\"" if @pagination_next_page_url
124
+ link_headers << "<#{@pagination_last_page_url}>; rel=\"last\"" if @pagination_last_page_url
112
125
  end
113
126
 
114
127
  link_header = link_headers.join(', ')
@@ -139,6 +152,30 @@ module APIHelper::Paginatable
139
152
  @pagination_per_page
140
153
  end
141
154
 
155
+ def pagination_items_count
156
+ @pagination_items_count
157
+ end
158
+
159
+ def pagination_pages_count
160
+ @pagination_pages_count
161
+ end
162
+
163
+ def pagination_first_page_url
164
+ @pagination_first_page_url
165
+ end
166
+
167
+ def pagination_prev_page_url
168
+ @pagination_prev_page_url
169
+ end
170
+
171
+ def pagination_next_page_url
172
+ @pagination_next_page_url
173
+ end
174
+
175
+ def pagination_last_page_url
176
+ @pagination_last_page_url
177
+ end
178
+
142
179
  alias_method :paginate_with, :pagination_per_page
143
180
 
144
181
  def add_or_replace_uri_param(url, param_name, param_value) # :nodoc:
@@ -1,3 +1,3 @@
1
1
  module APIHelper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neson