Class: Grape::Formatter::Paginater::PageLinks
- Inherits:
-
Object
- Object
- Grape::Formatter::Paginater::PageLinks
- Includes:
- Constants
- Defined in:
- lib/paginater/page/page_links.rb
Constant Summary collapse
- DELIM_LINKS =
",".freeze
Constants included from Constants
Constants::DefaultPage, Constants::DefaultPageSize, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::KaminariParam, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OneHour, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::SetCookie, Constants::SimpleParam, Constants::WrapperParam
Instance Attribute Summary collapse
-
#first ⇒ Object
Returns the value of attribute first.
-
#last ⇒ Object
Returns the value of attribute last.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
Instance Method Summary collapse
-
#initialize(response_headers) ⇒ PageLinks
constructor
let(:header) { => “<api.com/users?page=4&size=20>; rel="next", <…>; rel="last", <…>; rel="first", <…>; rel="prev"”.
Constructor Details
#initialize(response_headers) ⇒ PageLinks
let(:header) { => “<api.com/users?page=4&size=20>; rel="next", <…>; rel="last", <…>; rel="first", <…>; rel="prev"”
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/paginater/page/page_links.rb', line 20 def initialize(response_headers) link_header = response_headers[HEADER_LINK] if link_header return unless link_header =~ /(next|first|last|prev)/ link_header.split(DELIM_LINKS).each do |link| if link.strip =~ /<([^>]+)>; rel=\"([^\"]+)\"/ url_part, = $1, $2 next if !url_part || ! case when META_FIRST self.first = url_part when META_LAST self.last = url_part when META_NEXT self.next = url_part when META_PREV self.prev = url_part end end end else # When on the first page self.next = response_headers[HEADER_NEXT] self.last = response_headers[HEADER_LAST] end end |
Instance Attribute Details
#first ⇒ Object
Returns the value of attribute first.
11 12 13 |
# File 'lib/paginater/page/page_links.rb', line 11 def first @first end |
#last ⇒ Object
Returns the value of attribute last.
11 12 13 |
# File 'lib/paginater/page/page_links.rb', line 11 def last @last end |
#next ⇒ Object
Returns the value of attribute next.
11 12 13 |
# File 'lib/paginater/page/page_links.rb', line 11 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
11 12 13 |
# File 'lib/paginater/page/page_links.rb', line 11 def prev @prev end |