Class: Gitlab::Headers::PageLinks
- Inherits:
-
Object
- Object
- Gitlab::Headers::PageLinks
- Defined in:
- lib/gitlab/headers/page_links.rb
Constant Summary collapse
- HEADER_LINK =
'link'- DELIM_LINKS =
','- LINK_REGEX =
/<([^>]+)>; rel="([^"]+)"/- METAS =
%w[last next first prev].freeze
Instance Method Summary collapse
- #extract_links(header) ⇒ Object
-
#initialize(headers) ⇒ PageLinks
constructor
A new instance of PageLinks.
Constructor Details
#initialize(headers) ⇒ PageLinks
Returns a new instance of PageLinks.
13 14 15 16 17 |
# File 'lib/gitlab/headers/page_links.rb', line 13 def initialize(headers) link_header = headers[HEADER_LINK] extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/ end |
Instance Method Details
#extract_links(header) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/headers/page_links.rb', line 19 def extract_links(header) header.split(DELIM_LINKS).each do |link| LINK_REGEX.match(link.strip) do |match| url = match[1] = match[2] next if !url || ! || METAS.index().nil? send("#{}=", url) end end end |