link-header-parser 4.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173d1c05e3a5c2fe7d8e99454249d73ce780cfcc3bb120d7be5145e9b376ea54
4
- data.tar.gz: a79af8ae39af06d3a4625eab54aa8f51d4574f5789c913d570919c20f877febc
3
+ metadata.gz: c9b629542a562a00905799bef5712836047d11c01164ebd1fa51f9d710741edb
4
+ data.tar.gz: 470f3e29a6da3ac405fbf16dddc99a394734d5743717ea53633e8845387dc7ba
5
5
  SHA512:
6
- metadata.gz: 48085ca777ca8b2e6d859e2920165d7336cd2b909efbdfcc63aaff1980859d77e8cb6f0455dc61c8b089d143206d435639b49a9aef9a7f151c21ca683e9af07d
7
- data.tar.gz: 8fbd4c92cced717fc2a41d213209067824288810d14053236e6ca3ee1363c421a89c49be4ac6f34f9cc3736c91108ec58779a2638fca1efcbbf314ae5bbf1c84
6
+ metadata.gz: 779b4826009b1bd94856a17a2789c9cf54f440429543fde806d94ad47ba92c4fec80d981e5d8e60538f94f95ffa5a8e756bd4caff4a46ea6b5b1216ebd1edbfe
7
+ data.tar.gz: 489bec068d9c42302bc233339aa37d602ce189ad09e27d8fb2593eeb1cba0e84f4c1b0de8ecbac12b3902bbdc577640c38f5af437b04559c33a5fb930e886c3f
data/CHANGELOG.md CHANGED
@@ -1,11 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.1 / 2023-12-08
4
+
5
+ - Refactor test suite (7a9a446)
6
+ - Miscellaneous RuboCop updates (512efa5, cc36a1e, 025d150, 36f9cc1)
7
+ - Update RuboCop configuration (376cf8e)
8
+ - Update development Ruby to 2.7.8 (5ca0757)
9
+ - Remove Bundler ecosystem config from Dependabot (8bcacdf)
10
+ - Update RSpec configuration (afef67d, 83583a1)
11
+ - Remove `code-scanning-rubocop` and `rspec-github` gems (154fd95)
12
+
13
+ ## 5.0.0 / 2022-11-09
14
+
15
+ - **Breaking change:** Add `#to_ary`/`#to_a` method to `LinkHeadersCollection` (6a478ed)
16
+ - Note: marking this as a breaking change since it changes the existing behavior to return an `Array` of `Hash`es instead of an `Array` of `LinkHeader`s
17
+ - **Breaking change:** Update project Ruby version to 2.7.6 and minimum Ruby version to 2.7 (1e9df45)
18
+ - Improve documentation and privatize constants (8a68aa0)
19
+ - Remove Reek development dependency (423bc7a)
20
+ - Use ruby/debug gem instead of pry-byebug (4cd9d26)
21
+
3
22
  ## 4.0.0 / 2022-01-06
4
23
 
5
24
  - Remove Addressable dependency (daedf22)
6
25
  - **Breaking change:** Update minimum Ruby version to 2.6 (e2343ed)
7
26
  - Migrate to GitHub Actions (509b2c4)
8
- - Update project Ruby version to 2.6.9 (c39bc66)
27
+ - Update project Ruby version to 2.6.10 (c39bc66)
9
28
 
10
29
  ## 3.0.0 / 2021-05-22
11
30
 
@@ -26,9 +45,9 @@
26
45
  ## 2.0.0 / 2020-05-21
27
46
 
28
47
  - **Breaking changes:** Rewrite gem code (5351010)
29
- - `LinkHeaderParser.parse` returns `LinkHeadersCollection`
30
- - New classes: `LinkHeadersCollection`, `LinkHeader`, and `LinkHeaderParameter`
31
- - Renamed collection's `by_relation_type` method to `group_by_relation_type`
48
+ - `LinkHeaderParser.parse` returns `LinkHeadersCollection`
49
+ - New classes: `LinkHeadersCollection`, `LinkHeader`, and `LinkHeaderParameter`
50
+ - Renamed collection's `by_relation_type` method to `group_by_relation_type`
32
51
  - **Breaking change:** Update project Ruby version to 2.5.8 and minimum Ruby version to 2.5 (05b2e82)
33
52
  - Update inline documentation and refactor `ParsedHeader` and `ParsedHeaderCollection` classes (31ec43e)
34
53
 
data/README.md CHANGED
@@ -4,30 +4,22 @@
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/link-header-parser.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
6
6
  [![Downloads](https://img.shields.io/gem/dt/link-header-parser.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
7
- [![Build](https://img.shields.io/github/workflow/status/jgarber623/link-header-parser-ruby/CI?logo=github&style=for-the-badge)](https://github.com/jgarber623/link-header-parser-ruby/actions/workflows/ci.yml)
8
- [![Maintainability](https://img.shields.io/codeclimate/maintainability/jgarber623/link-header-parser-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby)
9
- [![Coverage](https://img.shields.io/codeclimate/c/jgarber623/link-header-parser-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby/code)
7
+ [![Build](https://img.shields.io/github/actions/workflow/status/jgarber623/link-header-parser-ruby/ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/jgarber623/link-header-parser-ruby/actions/workflows/ci.yml)
10
8
 
11
9
  ## Getting Started
12
10
 
13
- Before installing and using link-header-parser-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.6 (or newer) installed. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm).
11
+ Before installing and using link-header-parser-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. Using a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended.
14
12
 
15
- link-header-parser-ruby is developed using Ruby 2.6.9 and is additionally tested against Ruby 2.7, 3.0, and 3.1 using [GitHub Actions](https://github.com/jgarber623/link-header-parser-ruby/actions).
13
+ link-header-parser-ruby is developed using Ruby 2.7.8 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/jgarber623/link-header-parser-ruby/actions).
16
14
 
17
15
  ## Installation
18
16
 
19
- If you're using [Bundler](https://bundler.io), add link-header-parser-ruby to your project's `Gemfile`:
17
+ Add link-header-parser-ruby to your project's `Gemfile` and run `bundle install`:
20
18
 
21
19
  ```ruby
22
- source 'https://rubygems.org'
20
+ source "https://rubygems.org"
23
21
 
24
- gem 'link-header-parser'
25
- ```
26
-
27
- …and hop over to your command prompt and run…
28
-
29
- ```sh
30
- $ bundle install
22
+ gem "link-header-parser"
31
23
  ```
32
24
 
33
25
  ## Usage
@@ -35,14 +27,13 @@ $ bundle install
35
27
  With link-header-parser-ruby added to your project's `Gemfile` and installed, you may parse a URL's HTTP Link headers by doing:
36
28
 
37
29
  ```ruby
38
- require 'http'
39
- require 'link-header-parser'
30
+ require "net/http"
31
+ require "link-header-parser"
40
32
 
41
- response = HTTP.get('https://sixtwothree.org')
33
+ url = "https://sixtwothree.org"
34
+ link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields("Link")
42
35
 
43
- link_headers = response.headers.get('link')
44
-
45
- collection = LinkHeaderParser.parse(link_headers, base: response.uri)
36
+ collection = LinkHeaderParser.parse(link_headers, base: url)
46
37
  ```
47
38
 
48
39
  The `parse` method accepts two arguments:
@@ -94,7 +85,7 @@ You may interact with one or more `LinkHeader`s in a `LinkHeadersCollection` usi
94
85
  #### Link Target ([§ 3.1](https://tools.ietf.org/html/rfc8288#section-3.1))
95
86
 
96
87
  ```ruby
97
- link_header = LinkHeaderParser.parse('</index.html>; rel="home"', base: 'https://example.com/').first
88
+ link_header = LinkHeaderParser.parse(%(</index.html>; rel="home"), base: "https://example.com/").first
98
89
 
99
90
  link_header.target_string
100
91
  #=> "/index.html"
@@ -108,7 +99,7 @@ The `target_string` method returns a string of the value between the opening and
108
99
  #### Link Context ([§ 3.2](https://tools.ietf.org/html/rfc8288#section-3.2))
109
100
 
110
101
  ```ruby
111
- link_header = LinkHeaderParser.parse('</chapters/1>; anchor="#copyright"; rel="license"', base: 'https://example.com/').first
102
+ link_header = LinkHeaderParser.parse(%(</chapters/1>; anchor="#copyright"; rel="license"), base: "https://example.com/").first
112
103
 
113
104
  link_header.context_string
114
105
  #=> "#copyright"
@@ -122,7 +113,7 @@ The `anchor` parameter's value may be a fragment identifier (e.g. `#foo`), a rel
122
113
  #### Relation Type ([§ 3.3](https://tools.ietf.org/html/rfc8288#section-3.3))
123
114
 
124
115
  ```ruby
125
- link_header = LinkHeaderParser.parse('</chapters/1>; rel="prev start"', base: 'https://example.com/').first
116
+ link_header = LinkHeaderParser.parse(%(</chapters/1>; rel="prev start"), base: "https://example.com/").first
126
117
 
127
118
  link_header.relations_string
128
119
  #=> "prev start"
@@ -134,7 +125,7 @@ link_header.relation_types
134
125
  #### Link Parameters ([Appendix B.3](https://tools.ietf.org/html/rfc8288#appendix-B.3))
135
126
 
136
127
  ```ruby
137
- link_header = LinkHeaderParser.parse('</posts.rss>; rel="alternate"; hreflang="en-US"; title="sixtwothree.org: Posts"; type="application/rss+xml"', base: 'https://sixtwothree.org').first
128
+ link_header = LinkHeaderParser.parse(%(</posts.rss>; rel="alternate"; hreflang="en-US"; title="sixtwothree.org: Posts"; type="application/rss+xml"), base: "https://sixtwothree.org").first
138
129
 
139
130
  link_header.link_parameters
140
131
  #=> [#<LinkHeaderParser::LinkHeaderParameter name: "rel", value: "alternate">, #<LinkHeaderParser::LinkHeaderParameter name: "hreflang", value: "en-US">, #<LinkHeaderParser::LinkHeaderParameter name: "title", value: "sixtwothree.org: Posts">, #<LinkHeaderParser::LinkHeaderParameter name: "type", value: "application/rss+xml">]
@@ -142,10 +133,6 @@ link_header.link_parameters
142
133
 
143
134
  Note that the `Array` returned by the `link_parameters` method may include multiple `LinkHeaderParameter`s with the same name depending on the provided Link header. Certain methods on `LinkHeader` will return values from the first occurrence of a parameter name (e.g. `link_header.relations_string`) in accordance with [RFC-8288](https://tools.ietf.org/html/rfc8288).
144
135
 
145
- ## Contributing
146
-
147
- Interested in helping improve link-header-parser-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/jgarber623/link-header-parser-ruby/blob/main/CONTRIBUTING.md) for details.
148
-
149
136
  ## Acknowledgments
150
137
 
151
138
  link-header-parser-ruby is written and maintained by [Jason Garber](https://sixtwothree.org).
@@ -1,19 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
3
+ require "forwardable"
4
4
 
5
- require_relative 'link_header_parser/version'
5
+ require_relative "link_header_parser/version"
6
6
 
7
- require_relative 'link_header_parser/link_header'
8
- require_relative 'link_header_parser/link_header_parameter'
9
- require_relative 'link_header_parser/link_headers_collection'
7
+ require_relative "link_header_parser/link_header"
8
+ require_relative "link_header_parser/link_header_parameter"
9
+ require_relative "link_header_parser/link_headers_collection"
10
10
 
11
11
  module LinkHeaderParser
12
- # Parse an array of HTTP Link headers
12
+ # Parse an array of HTTP Link headers.
13
13
  #
14
- # @param headers [Array<String>]
15
- # @param base [String]
16
- # @return [LinkHeaderParser::LinkHeadersCollection]
14
+ # Convenience method for {LinkHeaderParser::LinkHeadersCollection#initialize}.
15
+ #
16
+ # @example
17
+ # require "net/http"
18
+ #
19
+ # url = "https://sixtwothree.org"
20
+ # link_headers = Net::HTTP.get_response(URI.parse(url)).get_fields("Link")
21
+ #
22
+ # LinkHeaderParser.parse(link_headers, base: url)
23
+ #
24
+ # @param (see LinkHeaderParser::LinkHeadersCollection#initialize)
25
+ # @return (see LinkHeaderParser::LinkHeadersCollection#initialize)
17
26
  def self.parse(*headers, base:)
18
27
  LinkHeadersCollection.new(*headers, base: base)
19
28
  end
@@ -3,30 +3,43 @@
3
3
  module LinkHeaderParser
4
4
  class LinkHeader
5
5
  FIELD_VALUE_REGEXP_PATTERN = /^\s*<\s*(?<target_string>[^>]+)\s*>\s*(?<parameters>;\s*.*)$/.freeze
6
- PARAMETERS_REGEXP_PATTERN = /(?<!;)\s*([^;]+)/.freeze
6
+ private_constant :FIELD_VALUE_REGEXP_PATTERN
7
7
 
8
+ PARAMETERS_REGEXP_PATTERN = /(?<!;)\s*[^;]+/.freeze
9
+ private_constant :PARAMETERS_REGEXP_PATTERN
10
+
11
+ # The +String+ value used to create this {LinkHeader}.
12
+ #
13
+ # @return [String]
8
14
  attr_reader :field_value
9
15
 
10
- # Create a new parsed Link header
16
+ # Create a new parsed Link header.
17
+ #
11
18
  # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
19
+ # IETF RFC 8288 Web Linking Appendix B.2 Parsing a Link Field Value
12
20
  #
13
- # @param field_value [String]
14
- # @param base [String]
21
+ # @param field_value [String, #to_str]
22
+ # @param base [String, #to_str]
15
23
  def initialize(field_value, base:)
16
24
  @field_value = field_value.to_str
17
25
  @base = base.to_str
18
26
  end
19
27
 
20
- # The context URL for this Link header extracted from field_value (or target URL if no context URL is present)
21
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.11)
28
+ # The context URL for this Link header extracted from +field_value+ (or
29
+ # target URL if no context URL is present).
30
+ #
31
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
32
+ # IETF RFC 8288 Web Linking Appendix B.2.2.11 Parsing a Link Field Value
22
33
  #
23
34
  # @return [String]
24
35
  def context_string
25
36
  @context_string ||= grouped_link_parameters[:anchor]&.first || target_string
26
37
  end
27
38
 
28
- # The resolved context URL for this Link header
29
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.12)
39
+ # The resolved context URL for this Link header.
40
+ #
41
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
42
+ # IETF RFC 8288 Web Linking Appendix B.2.2.12 Parsing a Link Field Value
30
43
  #
31
44
  # @return [String]
32
45
  def context_uri
@@ -40,48 +53,62 @@ module LinkHeaderParser
40
53
  "relation_types: #{relation_types.inspect}>"
41
54
  end
42
55
 
43
- # The parsed parameters for this Link header extracted from field_value
56
+ # The parsed parameters for this Link header extracted from +field_value+.
57
+ #
44
58
  # @see https://tools.ietf.org/html/rfc8288#appendix-B.3
59
+ # IETF RFC 8288 Web Linking Appendix B.3 Parsing Parameters
45
60
  #
46
61
  # @return [Array<LinkHeaderParser::LinkHeaderParameter>]
47
62
  def link_parameters
48
- @link_parameters ||= field_value_match_data[:parameters].scan(PARAMETERS_REGEXP_PATTERN)
49
- .flatten
50
- .map { |parameter| LinkHeaderParameter.new(parameter) }
63
+ @link_parameters ||= field_value_match_data[:parameters]
64
+ .scan(PARAMETERS_REGEXP_PATTERN)
65
+ .map { |parameter| LinkHeaderParameter.new(parameter.strip) }
51
66
  end
52
67
 
53
- # The relations_string value returned as an Array
54
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.10 and Appendix B.2.2.17.1)
68
+ # The +relations_string+ value returned as an +Array+.
69
+ #
70
+ # @see LinkHeader#relations_string
71
+ #
72
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
73
+ # IETF RFC 8288 Web Linking Appendix B.2.2.10 and Appendix B.2.2.17.1 Parsing a Link Field Value
55
74
  #
56
75
  # @return [Array<String>]
57
76
  def relation_types
58
77
  @relation_types ||= relations_string.split.map(&:downcase)
59
78
  end
60
79
 
61
- # The relation types for this Link header extracted from field_value
62
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.9)
80
+ # The relation types for this Link header extracted from +field_value+.
81
+ #
82
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
83
+ # IETF RFC 8288 Web Linking Appendix B.2.2.9 Parsing a Link Field Value
63
84
  #
64
85
  # @return [String]
65
86
  def relations_string
66
87
  @relations_string ||= grouped_link_parameters[:rel]&.first.to_s
67
88
  end
68
89
 
69
- # The target URL for this Link header extracted from field_value
70
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.4)
90
+ # The target URL for this Link header extracted from +field_value+
91
+ #
92
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
93
+ # IETF RFC 8288 Web Linking Appendix B.2.2.4 Parsing a Link Field Value
71
94
  #
72
95
  # @return [String]
73
96
  def target_string
74
97
  @target_string ||= field_value_match_data[:target_string]
75
98
  end
76
99
 
77
- # The resolved target URL for this Link header
78
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.2 (Appendix B.2.2.8)
100
+ # The resolved target URL for this Link header.
101
+ #
102
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.2
103
+ # IETF RFC 8288 Web Linking Appendix B.2.2.8 Parsing a Link Field Value
79
104
  #
80
105
  # @return [String]
81
106
  def target_uri
82
107
  @target_uri ||= URI.join(base, target_string).normalize.to_s
83
108
  end
84
109
 
110
+ # Return a +Hash+ representation of this {LinkHeader}.
111
+ #
85
112
  # @return [Hash{Symbol => String, Array, Hash{Symbol => Array}}]
86
113
  def to_hash
87
114
  {
@@ -106,10 +133,11 @@ module LinkHeaderParser
106
133
  end
107
134
 
108
135
  def grouped_link_parameters
109
- @grouped_link_parameters ||= link_parameters.map(&:to_a)
110
- .group_by(&:shift)
111
- .transform_keys(&:to_sym)
112
- .transform_values(&:flatten)
136
+ @grouped_link_parameters ||= link_parameters
137
+ .map(&:to_a)
138
+ .group_by(&:shift)
139
+ .transform_keys(&:to_sym)
140
+ .transform_values(&:flatten)
113
141
  end
114
142
  end
115
143
  end
@@ -3,10 +3,16 @@
3
3
  module LinkHeaderParser
4
4
  class LinkHeaderParameter
5
5
  PARAMETER_REGEXP_PATTERN = /^(?<name>.+?)(?:="?(?<value>.*?)"?)?$/.freeze
6
+ private_constant :PARAMETER_REGEXP_PATTERN
6
7
 
8
+ # The +String+ value used to create this {LinkHeaderParameter}.
9
+ #
10
+ # @return [String]
7
11
  attr_reader :parameter
8
12
 
9
- # @param parameter [String]
13
+ # Create a new parsed Link header parameter.
14
+ #
15
+ # @param parameter [String, #to_str]
10
16
  def initialize(parameter)
11
17
  @parameter = parameter.to_str
12
18
  end
@@ -18,20 +24,24 @@ module LinkHeaderParser
18
24
  "value: #{value.inspect}>"
19
25
  end
20
26
 
21
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.3 (Appendix B.3.2.9)
27
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.3
28
+ # IETF RFC 8288 Web Linking Appendix B.3.2.9 Parsing Parameters
22
29
  #
23
30
  # @return [String]
24
31
  def name
25
32
  @name ||= parameter_match_data[:name].downcase
26
33
  end
27
34
 
28
- # @see https://tools.ietf.org/html/rfc8288#appendix-B.3 (Appendix B.3.2.8)
35
+ # @see https://tools.ietf.org/html/rfc8288#appendix-B.3
36
+ # IETF RFC 8288 Web Linking Appendix B.3.2.8 Parsing Parameters
29
37
  #
30
38
  # @return [String]
31
39
  def value
32
40
  @value ||= parameter_match_data[:value].to_s
33
41
  end
34
42
 
43
+ # Return an +Array+ representation of this {LinkHeaderParameter}.
44
+ #
35
45
  # @return [Array<String>]
36
46
  def to_ary
37
47
  [name, value]
@@ -8,17 +8,28 @@ module LinkHeaderParser
8
8
 
9
9
  def_delegators :members, :[], :<<, :each, :last, :length, :push
10
10
 
11
+ # The +Array+ of HTTP Link headers used to create this
12
+ # {LinkHeadersCollection}.
13
+ #
14
+ # @return [Array<String>]
11
15
  attr_reader :headers
12
16
 
13
- # @param headers [Array<String>]
14
- # @param base [String]
17
+ # Parse an array of HTTP Link headers.
18
+ #
19
+ # @param headers [Array<String, #to_str>]
20
+ # @param base [String, #to_str]
15
21
  def initialize(*headers, base:)
22
+ # rubocop:disable Performance/ChainArrayAllocation
16
23
  @headers = headers.to_ary.flatten.map(&:to_str)
24
+ # rubocop:enable Performance/ChainArrayAllocation
17
25
  @base = base.to_str
18
26
 
19
- distinct_headers.each { |header| push(LinkHeader.new(header, base: base)) }
27
+ push(*distinct_link_headers)
20
28
  end
21
29
 
30
+ # Retrieve a +Hash+ of this collection's {LinkHeader}s grouped by their
31
+ # relation type(s).
32
+ #
22
33
  # @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
23
34
  def group_by_relation_type
24
35
  relation_types.to_h do |relation_type|
@@ -33,17 +44,33 @@ module LinkHeaderParser
33
44
  "relation_types: #{relation_types.inspect}>"
34
45
  end
35
46
 
47
+ # Retrieve a unique sorted +Array+ of this collection's {LinkHeader}
48
+ # relation types.
49
+ #
36
50
  # @return [Array<String>]
37
51
  def relation_types
38
- @relation_types ||= flat_map(&:relation_types).uniq.sort
52
+ @relation_types ||= Set.new(flat_map(&:relation_types)).to_a.sort
53
+ end
54
+
55
+ # Return an +Array+ representation of this {LinkHeadersCollection}.
56
+ #
57
+ # @see LinkHeader#to_hash
58
+ #
59
+ # @return [Array<Hash>}>]
60
+ def to_ary
61
+ map(&:to_hash)
39
62
  end
40
63
 
64
+ alias to_a to_ary
65
+
41
66
  private
42
67
 
43
68
  attr_reader :base
44
69
 
45
- def distinct_headers
46
- @distinct_headers ||= headers.flat_map { |header| header.split(/,(?=[\s|<])/) }.map(&:strip)
70
+ def distinct_link_headers
71
+ headers
72
+ .flat_map { |header| header.split(/,(?=[\s|<])/) }
73
+ .map { |header| LinkHeader.new(header.strip, base: base) }
47
74
  end
48
75
 
49
76
  def members
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LinkHeaderParser
4
- VERSION = '4.0.0'
4
+ VERSION = "5.0.1"
5
5
  end
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/link_header_parser/version'
3
+ require_relative "lib/link_header_parser/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 2.6', '< 4'
6
+ spec.required_ruby_version = ">= 2.7", "< 4"
7
7
 
8
- spec.name = 'link-header-parser'
8
+ spec.name = "link-header-parser"
9
9
  spec.version = LinkHeaderParser::VERSION
10
- spec.authors = ['Jason Garber']
11
- spec.email = ['jason@sixtwothree.org']
10
+ spec.authors = ["Jason Garber"]
11
+ spec.email = ["jason@sixtwothree.org"]
12
12
 
13
- spec.summary = 'Parse HTTP Link headers.'
13
+ spec.summary = "Parse HTTP Link headers."
14
14
  spec.description = spec.summary
15
- spec.homepage = 'https://github.com/jgarber623/link-header-parser-ruby'
16
- spec.license = 'MIT'
15
+ spec.homepage = "https://github.com/jgarber623/link-header-parser-ruby"
16
+ spec.license = "MIT"
17
17
 
18
- spec.files = Dir['lib/**/*'].reject { |f| File.directory?(f) }
19
- spec.files += %w[LICENSE CHANGELOG.md CONTRIBUTING.md README.md]
18
+ spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
19
+ spec.files += %w[LICENSE CHANGELOG.md README.md]
20
20
  spec.files += %w[link-header-parser.gemspec]
21
21
 
22
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
23
23
 
24
24
  spec.metadata = {
25
- 'bug_tracker_uri' => "#{spec.homepage}/issues",
26
- 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
27
- 'rubygems_mfa_required' => 'true'
25
+ "bug_tracker_uri" => "#{spec.homepage}/issues",
26
+ "changelog_uri" => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
27
+ "rubygems_mfa_required" => "true"
28
28
  }
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link-header-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2023-12-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse HTTP Link headers.
14
14
  email:
@@ -18,7 +18,6 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - CHANGELOG.md
21
- - CONTRIBUTING.md
22
21
  - LICENSE
23
22
  - README.md
24
23
  - lib/link-header-parser.rb
@@ -32,7 +31,7 @@ licenses:
32
31
  - MIT
33
32
  metadata:
34
33
  bug_tracker_uri: https://github.com/jgarber623/link-header-parser-ruby/issues
35
- changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v4.0.0/CHANGELOG.md
34
+ changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v5.0.1/CHANGELOG.md
36
35
  rubygems_mfa_required: 'true'
37
36
  post_install_message:
38
37
  rdoc_options: []
@@ -42,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
- version: '2.6'
44
+ version: '2.7'
46
45
  - - "<"
47
46
  - !ruby/object:Gem::Version
48
47
  version: '4'
@@ -52,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
51
  - !ruby/object:Gem::Version
53
52
  version: '0'
54
53
  requirements: []
55
- rubygems_version: 3.2.33
54
+ rubygems_version: 3.1.6
56
55
  signing_key:
57
56
  specification_version: 4
58
57
  summary: Parse HTTP Link headers.
data/CONTRIBUTING.md DELETED
@@ -1,37 +0,0 @@
1
- # Contributing to link-header-parser-ruby
2
-
3
- There are a couple ways you can help improve link-header-parser-ruby:
4
-
5
- 1. Fix an existing [issue][issues] and submit a [pull request][pulls].
6
- 1. Review open [pull requests][pulls].
7
- 1. Report a new [issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
8
-
9
- ## Getting Started
10
-
11
- link-header-parser-ruby is developed using Ruby 2.6.9 and is additionally tested against Ruby 2.7, 3.0, and 3.1 using [GitHub Actions](https://github.com/jgarber623/link-header-parser-ruby/actions).
12
-
13
- Before making changes to link-header-parser-ruby, you'll want to install Ruby 2.6.9. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.6.9 using your method of choice, install the project's gems by running:
14
-
15
- ```sh
16
- bundle install
17
- ```
18
-
19
- ## Making Changes
20
-
21
- 1. Fork and clone the project's repo.
22
- 1. Install development dependencies as outlined above.
23
- 1. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
24
- 1. _Write some code!_
25
- 1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bin/ci`.
26
- 1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://chris.beams.io/posts/git-commit/) for tips on writing useful Git commit messages.)_
27
- 1. Push the branch to your fork: `git push -u origin my-new-feature`.
28
- 1. Create a new [pull request][pulls] and we'll review your changes.
29
-
30
- ## Code Style
31
-
32
- Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org) syntax. There are [plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended you install the EditorConfig plugin for your editor of choice.
33
-
34
- Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
35
-
36
- [issues]: https://github.com/jgarber623/link-header-parser-ruby/issues
37
- [pulls]: https://github.com/jgarber623/link-header-parser-ruby/pulls