link-header-parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitignore +34 -0
- data/.reek.yml +9 -0
- data/.rspec +2 -0
- data/.rubocop +3 -0
- data/.rubocop.yml +22 -0
- data/.ruby-version +1 -0
- data/.simplecov +11 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +92 -0
- data/Rakefile +18 -0
- data/lib/link-header-parser.rb +17 -0
- data/lib/link_header_parser/exceptions.rb +5 -0
- data/lib/link_header_parser/parsed_header.rb +57 -0
- data/lib/link_header_parser/parsed_header_collection.rb +58 -0
- data/lib/link_header_parser/version.rb +3 -0
- data/link-header-parser.gemspec +38 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2af19382d4d537959b66ca55c6fcfab4cc52cb552748e6cc9cbf7d18176491e1
|
4
|
+
data.tar.gz: f576800eaa08e75441edf34b65bac17302cbff52ad161ad84e5604fdd8a66890
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0823f00fe68edffc867354972a4e3efa4f7f4ebe5cd4ba14ff0dbefe7a291531daca5b789f3392d0b53a9231edc1261f4ea01c094545a74119aed0c9c7f668d
|
7
|
+
data.tar.gz: 9bf55d725122524374d47024900768bb497239422e826a0d07f66052e091dc950f982e8df3d4275d75837d8e4b3e19bbaa92a8aa5f937299f2429b66e02ee215
|
data/.editorconfig
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# EditorConfig is awesome: https://EditorConfig.org
|
2
|
+
root = true
|
3
|
+
|
4
|
+
[*]
|
5
|
+
charset = utf-8
|
6
|
+
end_of_line = lf
|
7
|
+
insert_final_newline = true
|
8
|
+
indent_size = 2
|
9
|
+
indent_style = space
|
10
|
+
trim_trailing_whitespace = true
|
11
|
+
|
12
|
+
[*.md]
|
13
|
+
indent_size = 4
|
14
|
+
indent_style = tab
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Documentation cache and generated files:
|
17
|
+
/.yardoc/
|
18
|
+
/_yardoc/
|
19
|
+
/doc/
|
20
|
+
/rdoc/
|
21
|
+
|
22
|
+
# Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.reek.yml
ADDED
data/.rspec
ADDED
data/.rubocop
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
Layout/AlignHash:
|
6
|
+
EnforcedHashRocketStyle: table
|
7
|
+
|
8
|
+
Metrics/LineLength:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Naming/FileName:
|
12
|
+
Exclude:
|
13
|
+
- lib/link-header-parser.rb
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/FrozenStringLiteralComment:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/SymbolArray:
|
22
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.6
|
data/.simplecov
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'simplecov-console'
|
2
|
+
|
3
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
4
|
+
|
5
|
+
if RSpec.configuration.files_to_run.length > 1
|
6
|
+
formatters << SimpleCov::Formatter::Console
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
|
11
|
+
end
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.4.6
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
6
|
+
cache:
|
7
|
+
- bundler
|
8
|
+
before_install:
|
9
|
+
- gem update --system
|
10
|
+
- gem install bundler
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
after_script:
|
16
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
17
|
+
notifications:
|
18
|
+
email: false
|
19
|
+
slack:
|
20
|
+
rooms:
|
21
|
+
secure: ZV5G4LIK9OXRXkXt3iC53QD1uVWmThzETj8CallRoZgGfUKfzzMjx2V7NqJLwkmFkaK9y/flt/bRVMVqkH60GY0Gq6YeS9zuKEWJYesC6+aWQa6scKaxgewLdfYth3ijMS91XbPKECbFj0LOs1WPTfqYDsdPpOnH2RBWUO6lx8ID4DZtvi7kMhcY2+K21Q3/3gW9y919KHSCppM24EsyIbkAlFce5RjXn5WmfyTOTyTrxbHyByFr3SSTGdyO3KK0Fa4hhKNC2pa5WmlLHvZ/c5P7MYf1Eo+Rji5I0QY3pcGOIvbK0xBBnXnGI6Zfp088evElGpw8qgUdkR03QbxjTYANdN6mlk9DvnHqPWjI6OalF3SA7PP9mYjKVb2THDPqWOAvqYdMrrLylduWfdCzpxk4Z13DwF6rYSRgz3juKeKx80rhcAFmptLAC3uzQxgSgKoj9xZbbcYqhh/JQL9lNBZYJyLO5M0fOzrEDbLyNrWFYzUgKYgxRAOLWhJ8V2FlN3oR2cXXcf6vmlpPYfoCA0a8Ig82Htapan0JEhNEU6sS1ctdS7NegccEB9P0V5hUDy3AooaqCy8gFYE3TENYI1vwrevo5vqtNffR1PXTsliGe/gIIeFET6H2IJ+HYG9DefMHwYIR97enMFe50PauNGqdHS9kCoUV59r1PDOBJuU=
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,37 @@
|
|
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.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.3 using [Travis CI](https://travis-ci.com/jgarber623/link-header-parser-ruby).
|
12
|
+
|
13
|
+
Before making changes to link-header-parser-ruby, you'll want to install Ruby 2.4.6. 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.4.6 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 `bundle exec rspec`.
|
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
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jason Garber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# link-header-parser-ruby
|
2
|
+
|
3
|
+
**A Ruby gem for parsing HTTP Link headers.**
|
4
|
+
|
5
|
+
[![Gem](https://img.shields.io/gem/v/link-header-parser.svg?style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
|
6
|
+
[![Downloads](https://img.shields.io/gem/dt/link-header-parser.svg?style=for-the-badge)](https://rubygems.org/gems/link-header-parser)
|
7
|
+
[![Build](https://img.shields.io/travis/com/jgarber623/link-header-parser-ruby/master.svg?style=for-the-badge)](https://travis-ci.com/jgarber623/link-header-parser-ruby)
|
8
|
+
[![Dependencies](https://img.shields.io/depfu/jgarber623/link-header-parser-ruby.svg?style=for-the-badge)](https://depfu.com/github/jgarber623/link-header-parser-ruby)
|
9
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/jgarber623/link-header-parser-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby)
|
10
|
+
[![Coverage](https://img.shields.io/codeclimate/c/jgarber623/link-header-parser-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/jgarber623/link-header-parser-ruby/code)
|
11
|
+
|
12
|
+
## Getting Started
|
13
|
+
|
14
|
+
Before installing and using link-header-parser-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.4 (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).
|
15
|
+
|
16
|
+
link-header-parser-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.3 using [Travis CI](https://travis-ci.com/jgarber623/link-header-parser-ruby).
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
If you're using [Bundler](https://bundler.io), add link-header-parser-ruby to your project's `Gemfile`:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
source 'https://rubygems.org'
|
24
|
+
|
25
|
+
gem 'link-header-parser'
|
26
|
+
```
|
27
|
+
|
28
|
+
…and hop over to your command prompt and run…
|
29
|
+
|
30
|
+
```sh
|
31
|
+
$ bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
With link-header-parser-ruby added to your project's `Gemfile` and installed, you may parse a URL's HTTP Link headers by doing:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'http'
|
40
|
+
require 'link-header-parser'
|
41
|
+
|
42
|
+
response = HTTP.get('https://sixtwothree.org')
|
43
|
+
|
44
|
+
link_headers = response.headers.get('link')
|
45
|
+
|
46
|
+
collection = LinkHeaderParser.parse(link_headers, base: response.uri.to_s)
|
47
|
+
|
48
|
+
puts collection.relation_types # => ["preconnect", "webmention"]
|
49
|
+
puts collection.map(&:target_uri) # => ["https://assets.sixtwothree.org/", "https://fonts.googleapis.com/", "https://fonts.gstatic.com/", "https://sixtwothree.org/webmentions"]
|
50
|
+
```
|
51
|
+
|
52
|
+
In the example above, `collection` is an instance of `ParsedHeaderCollection` which includes Ruby's [Enumerable](https://ruby-doc.org/core/Enumerable.html) mixin. This mixin allows for use of common methods like `each`, `first`/`last`, and `map` (as demonstrated above).
|
53
|
+
|
54
|
+
Additionally, `collection.by_relation_type` returns an `OpenStruct` with the following attributes:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
{
|
58
|
+
preconnect: [
|
59
|
+
#<LinkHeaderParser::ParsedHeader @header="<https://assets.sixtwothree.org/>; rel=\"preconnect\"">,
|
60
|
+
#<LinkHeaderParser::ParsedHeader @header="<https://fonts.googleapis.com/>; rel=\"preconnect\"">,
|
61
|
+
#<LinkHeaderParser::ParsedHeader @header="<https://fonts.gstatic.com/>; rel=\"preconnect\"">
|
62
|
+
],
|
63
|
+
webmention: [
|
64
|
+
#<LinkHeaderParser::ParsedHeader @header="<https://sixtwothree.org/webmentions>; rel=\"webmention\"">
|
65
|
+
]
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
Building on this example, you may interact with one or more `ParsedHeader`s in a `ParsedHeaderCollection`:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
parsed_header = collection.first
|
73
|
+
|
74
|
+
parsed_header.relation_types # => ['preconnect']
|
75
|
+
parsed_header.relations # => 'preconnect'
|
76
|
+
parsed_header.target # => 'https://assets.sixtwothree.org/'
|
77
|
+
parsed_header.target_uri # => 'https://assets.sixtwothree.org/'
|
78
|
+
```
|
79
|
+
|
80
|
+
The naming conventions for these methods draws heavily on the terminology established in [RFC-5988](https://tools.ietf.org/html/rfc5988) and [RFC-8288](https://tools.ietf.org/html/rfc8288).
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
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/master/CONTRIBUTING.md) for details.
|
85
|
+
|
86
|
+
## Acknowledgments
|
87
|
+
|
88
|
+
link-header-parser-ruby is written and maintained by [Jason Garber](https://sixtwothree.org).
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
link-header-parser-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'reek/rake/task'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
Reek::Rake::Task.new do |task|
|
8
|
+
task.fail_on_error = false
|
9
|
+
task.source_files = FileList['**/*.rb'].exclude('vendor/**/*.rb')
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new do |task|
|
15
|
+
task.fail_on_error = false
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: [:rubocop, :reek, :spec]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
require 'absolutely'
|
4
|
+
|
5
|
+
require 'link_header_parser/version'
|
6
|
+
require 'link_header_parser/exceptions'
|
7
|
+
|
8
|
+
require 'link_header_parser/parsed_header'
|
9
|
+
require 'link_header_parser/parsed_header_collection'
|
10
|
+
|
11
|
+
module LinkHeaderParser
|
12
|
+
class << self
|
13
|
+
def parse(*headers, base:)
|
14
|
+
ParsedHeaderCollection.new(headers, base: base)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module LinkHeaderParser
|
2
|
+
class ParsedHeader
|
3
|
+
attr_reader :header
|
4
|
+
|
5
|
+
def initialize(header, base:)
|
6
|
+
raise ArgumentError, "header must be a String (given #{header.class})" unless header.is_a?(String)
|
7
|
+
raise ArgumentError, "base must be a String (given #{base.class})" unless base.is_a?(String)
|
8
|
+
|
9
|
+
@header = header
|
10
|
+
@base = base
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
format(%(#<#{self.class.name}:%#0x @header="#{header.gsub('"', '\"')}">), object_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def parameters
|
18
|
+
@parameters ||= OpenStruct.new(header_attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def relation_types
|
22
|
+
@relation_types ||= relations&.split(' ') || nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def relations
|
26
|
+
@relations ||= parameters.rel || nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def target
|
30
|
+
@target ||= header_match_data[:target]
|
31
|
+
end
|
32
|
+
|
33
|
+
def target_uri
|
34
|
+
@target_uri ||= Absolutely.to_abs(base: @base, relative: target)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h
|
38
|
+
{
|
39
|
+
target: target,
|
40
|
+
target_uri: target_uri,
|
41
|
+
relations: relations,
|
42
|
+
relation_types: relation_types,
|
43
|
+
parameters: parameters.to_h
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def header_attributes
|
50
|
+
@header_attributes ||= header_match_data[:attributes].tr('"', '').split(';').map { |tuple| tuple.split('=').map(&:strip) }.sort.to_h
|
51
|
+
end
|
52
|
+
|
53
|
+
def header_match_data
|
54
|
+
@header_match_data ||= header.match(/^<\s*(?<target>[^>]+)\s*>\s*;\s*(?<attributes>.*)$/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module LinkHeaderParser
|
2
|
+
class ParsedHeaderCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :headers
|
6
|
+
|
7
|
+
def initialize(*headers, base:)
|
8
|
+
@headers = headers.flatten
|
9
|
+
@base = base
|
10
|
+
end
|
11
|
+
|
12
|
+
def by_relation_type
|
13
|
+
@by_relation_type ||= OpenStruct.new(mapped_relation_types)
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
return to_enum unless block_given?
|
18
|
+
|
19
|
+
parsed_headers.each { |parsed_header| yield parsed_header }
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
format(%(#<#{self.class.name}:%#0x @headers=#{headers}>), object_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def last
|
29
|
+
@last ||= parsed_headers[-1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def length
|
33
|
+
@length ||= parsed_headers.length
|
34
|
+
end
|
35
|
+
|
36
|
+
def relation_types
|
37
|
+
@relation_types ||= parsed_headers.map(&:relation_types).flatten.uniq.sort
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def find_all_by_relation_type(relation_type)
|
43
|
+
find_all { |parsed_header| parsed_header.relation_types.include?(relation_type) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def mapped_relation_types
|
47
|
+
@mapped_relation_types ||= relation_types.map { |relation_type| [relation_type, find_all_by_relation_type(relation_type)] }.to_h
|
48
|
+
end
|
49
|
+
|
50
|
+
def uniq_headers
|
51
|
+
@uniq_headers ||= headers.map { |header| header.split(/,(?=[\s|<])/) }.flatten.map(&:strip)
|
52
|
+
end
|
53
|
+
|
54
|
+
def parsed_headers
|
55
|
+
@parsed_headers ||= uniq_headers.map { |header| ParsedHeader.new(header, base: @base) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'link_header_parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.required_ruby_version = ['>= 2.4', '< 2.7']
|
8
|
+
|
9
|
+
spec.name = 'link-header-parser'
|
10
|
+
spec.version = LinkHeaderParser::VERSION
|
11
|
+
spec.authors = ['Jason Garber']
|
12
|
+
spec.email = ['jason@sixtwothree.org']
|
13
|
+
|
14
|
+
spec.summary = 'Parse HTTP Link headers.'
|
15
|
+
spec.description = spec.summary
|
16
|
+
spec.homepage = 'https://github.com/jgarber623/link-header-parser-ruby'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec)/}) }
|
20
|
+
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.metadata = {
|
24
|
+
'bug_tracker_uri' => "#{spec.homepage}/issues",
|
25
|
+
'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
|
26
|
+
}
|
27
|
+
|
28
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
29
|
+
spec.add_development_dependency 'reek', '~> 5.4'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.71.0'
|
32
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.3'
|
33
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.33'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
35
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.5.0'
|
36
|
+
|
37
|
+
spec.add_runtime_dependency 'absolutely', '~> 3.0'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: link-header-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Garber
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: reek
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.71.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.71.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.33'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.33'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.16.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.16.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov-console
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.5.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.5.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: absolutely
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
description: Parse HTTP Link headers.
|
140
|
+
email:
|
141
|
+
- jason@sixtwothree.org
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".editorconfig"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".reek.yml"
|
149
|
+
- ".rspec"
|
150
|
+
- ".rubocop"
|
151
|
+
- ".rubocop.yml"
|
152
|
+
- ".ruby-version"
|
153
|
+
- ".simplecov"
|
154
|
+
- ".travis.yml"
|
155
|
+
- CHANGELOG.md
|
156
|
+
- CONTRIBUTING.md
|
157
|
+
- Gemfile
|
158
|
+
- LICENSE
|
159
|
+
- README.md
|
160
|
+
- Rakefile
|
161
|
+
- lib/link-header-parser.rb
|
162
|
+
- lib/link_header_parser/exceptions.rb
|
163
|
+
- lib/link_header_parser/parsed_header.rb
|
164
|
+
- lib/link_header_parser/parsed_header_collection.rb
|
165
|
+
- lib/link_header_parser/version.rb
|
166
|
+
- link-header-parser.gemspec
|
167
|
+
homepage: https://github.com/jgarber623/link-header-parser-ruby
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
metadata:
|
171
|
+
bug_tracker_uri: https://github.com/jgarber623/link-header-parser-ruby/issues
|
172
|
+
changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v0.1.0/CHANGELOG.md
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '2.4'
|
182
|
+
- - "<"
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '2.7'
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
requirements: []
|
191
|
+
rubygems_version: 3.0.3
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Parse HTTP Link headers.
|
195
|
+
test_files: []
|