grape-pagination 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/lib/grape/pagination.rb
CHANGED
@@ -8,7 +8,7 @@ module Grape
|
|
8
8
|
autoload :Extensions, 'grape/pagination/extensions'
|
9
9
|
autoload :Helpers, 'grape/pagination/helpers'
|
10
10
|
autoload :Paginator, 'grape/pagination/paginator'
|
11
|
-
autoload :
|
11
|
+
autoload :LinkHeader, 'grape/pagination/link_header'
|
12
12
|
|
13
13
|
def self.configuration
|
14
14
|
@configuration ||= Configuration.new
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module Grape::Pagination
|
4
|
+
class LinkHeader
|
5
|
+
attr_reader :url
|
6
|
+
attr_reader :page_params
|
7
|
+
|
8
|
+
def initialize(url, page_params)
|
9
|
+
@url = url
|
10
|
+
@page_params = page_params
|
11
|
+
end
|
12
|
+
|
13
|
+
def next
|
14
|
+
Link.new(url, 'next', page_params.merge(page: page_params[:page] + 1))
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_rfc5988
|
18
|
+
%w[next].map { |link| __send__(link).to_s }.join(', ')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
class Link
|
24
|
+
attr_reader :url, :rel, :page_params
|
25
|
+
|
26
|
+
def initialize(url, rel, page_params)
|
27
|
+
@url, @rel, @page_params = url, rel, page_params
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
%(<#{uri.to_s}>; rel="#{rel}")
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def uri
|
37
|
+
@uri ||= begin
|
38
|
+
uri = Addressable::URI.parse(url)
|
39
|
+
uri.query_values = (uri.query_values || {}).merge(page_params.stringify_keys)
|
40
|
+
uri
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -110,7 +110,7 @@ files:
|
|
110
110
|
- lib/grape/pagination/configuration.rb
|
111
111
|
- lib/grape/pagination/extensions.rb
|
112
112
|
- lib/grape/pagination/helpers.rb
|
113
|
-
- lib/grape/pagination/
|
113
|
+
- lib/grape/pagination/link_header.rb
|
114
114
|
- lib/grape/pagination/paginator.rb
|
115
115
|
- lib/grape/pagination/version.rb
|
116
116
|
- spec/grape/pagination/paginator_spec.rb
|
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash: -
|
133
|
+
hash: -558737369971045906
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
none: false
|
136
136
|
requirements:
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
segments:
|
141
141
|
- 0
|
142
|
-
hash: -
|
142
|
+
hash: -558737369971045906
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
145
|
rubygems_version: 1.8.23
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'addressable/uri'
|
2
|
-
|
3
|
-
module Grape::Pagination
|
4
|
-
class Link
|
5
|
-
attr_reader :url
|
6
|
-
|
7
|
-
def initialize(url)
|
8
|
-
@url = url
|
9
|
-
end
|
10
|
-
|
11
|
-
def next
|
12
|
-
uri.dup.tap { |uri| uri.query_values = uri.query_values.merge('page' => uri.query_values['page'].to_i + 1) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_rfc5988
|
16
|
-
%w[next].map { |link| [__send__(link), link] }
|
17
|
-
.compact
|
18
|
-
.map { |(link, rel)| %(<#{link}>; rel="#{rel}") }
|
19
|
-
.join(', ')
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def uri
|
25
|
-
@uri ||= Addressable::URI.parse(url)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|