rack-link_headers 2.0.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 923b708b4765a8eb504d6d4337de4bcc21abd40a0509c0c7851e649b23777fe2
4
+ data.tar.gz: c4634d4822bf971fe5ed4c9af90e9756942b3d47c05024444e94c7d68ce951bb
5
+ SHA512:
6
+ metadata.gz: a0deb2f9e6382622c350932f7f42cecec4a7ecba8b82182aac914fffe1d74538b99d25195932eba609ed8e39389ff1fc23baf57970a9224253bc82d6675b1dff
7
+ data.tar.gz: 5e1ee525a5f8a6595c152bee35b4b6ae4be63e970a393e29d66b005bf7fe9c27bd3287c310c220e60b53d748656b965061d41e5c26f627a4497a530133b3e118
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Rack::LinkHeaders
2
- [![Build Status](https://travis-ci.org/jgraichen/rack-link_headers.png?branch=master)](https://travis-ci.org/jgraichen/rack-link_headers)
2
+
3
+ [![Build Status](https://github.com/jgraichen/rack-link_headers/workflows/Build/badge.svg?event=push)](https://github.com/jgraichen/rack-link_headers/actions?query=workflow%3ABuild)
3
4
 
4
5
  Easy Link header management for rack responses.
5
6
 
@@ -20,23 +21,28 @@ Or install it yourself as:
20
21
  ## Usage
21
22
 
22
23
  ```ruby
23
- response.link "rel", "http://abc.de/"
24
- response.link "rss", "http://test.host/feed.xml"
24
+ response.link "http://abc.de/", rel: :search
25
+ response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
25
26
  ```
26
27
  ```
27
28
  response.headers["Link"]
28
- # => <http://abc.de/> rel="rel", <http://test.host/feed.xml> rel="rss"
29
+ # => <http://abc.de/>; rel="rel", <http://test.host/feed.xml>; rel="rss"; type="application/rss+xml"
29
30
  ```
30
31
 
31
32
  Manual set Link header will be overridden. All links can be
32
33
  accessed via `links`:
33
34
 
34
35
  ```ruby
35
- response.link "rel", "http://abc.de/"
36
- response.link "rss", "http://test.host/feed.xml"
36
+ response.link "http://abc.de/", rel: :search
37
+ response.link "http://test.host/feed.xml", rel: :rss, type: "application/rss+xml"
37
38
 
38
39
  response.links
39
- # => [{:rel=>"rel", :url=>"http://abc.de/"}, {:rel=>"rss", :url=>"http://test.host/feed.xml"}]
40
+ # => [
41
+ # {:url=>"http://abc.de/",
42
+ # :params=>{:ref=>:search}},
43
+ # {:url=>"http://test.host/feed.xml",
44
+ # :params=>{:rel=>:rss, :type=>"application/rss+xml"}}
45
+ # ]
40
46
  ```
41
47
 
42
48
  ## Contributing
@@ -1,4 +1,6 @@
1
- require 'rack/link_headers/header_hash_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack/link_headers/helper'
2
4
 
3
5
  module Rack
4
6
  module LinkHeaders
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module Rack
6
+ module LinkHeaders
7
+ # Helper for easy adding link headers to rack responses.
8
+ module Helper
9
+ def self.included(base)
10
+ base.send :include, InstanceMethods
11
+ end
12
+
13
+ module InstanceMethods
14
+ # Add a new Link header to response headers. Requires
15
+ # a URL and a params hash. Does not escape or
16
+ # sanitize anything. Manual added Link headers will be
17
+ # overridden.
18
+ def link(url, params = {})
19
+ links << {url: url.to_s, params: params}
20
+
21
+ self['Link'] = links.to_a.map do |link|
22
+ "<#{link[:url]}>" + link[:params].keys.sort.map do |k|
23
+ "; #{k}=\"#{link[:params][k]}\""
24
+ end.join
25
+ end.join(', ')
26
+ end
27
+
28
+ def links
29
+ @links ||= []
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Rack::Response.include Rack::LinkHeaders::Helper
37
+ Rack::Response::Helpers.include Rack::LinkHeaders::Helper
38
+
39
+ if defined?(ActionDispatch::Response)
40
+ ActionDispatch::Response.include Rack::LinkHeaders::Helper
41
+ end
42
+ if defined?(ActionController::TestResponse)
43
+ ActionController::TestResponse.include Rack::LinkHeaders::Helper
44
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  module LinkHeaders
3
5
  module VERSION
4
6
  MAJOR = 2
5
- MINOR = 0
7
+ MINOR = 3
6
8
  PATCH = 0
7
9
  STAGE = nil
8
10
 
@@ -1,22 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  require 'rack/link_headers/version'
6
7
 
7
- Gem::Specification.new do |gem|
8
- gem.name = 'rack-link_headers'
9
- gem.version = Rack::LinkHeaders::VERSION
10
- gem.authors = ["Jan Graichen"]
11
- gem.email = ["jg@altimos.de"]
12
- gem.description = %q{Easy Link header management for rack responses.}
13
- gem.summary = %q{Easy Link header management for rack responses.}
14
- gem.homepage = ""
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'rack-link_headers'
10
+ spec.version = Rack::LinkHeaders::VERSION
11
+ spec.authors = ['Jan Graichen']
12
+ spec.email = ['jgraichen@altimos.de']
13
+ spec.summary = 'Easy Link header management for rack responses.'
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
15
16
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
17
+ spec.files = Dir['**/*'].grep(%r{^(
18
+ (bin|lib|test|spec|features)/|
19
+ (.*\.gemspec|.*LICENSE.*|.*README.*|.*CHANGELOG.*)
20
+ )}x)
21
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ['lib']
20
24
 
21
- gem.add_dependency 'rack'
25
+ spec.add_runtime_dependency 'rack'
22
26
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+
5
+ ACTIONPACK = !ENV['ACTIONPACK'].to_s.empty?
6
+
7
+ if ACTIONPACK
8
+ # For testing ActionDispatch::Response
9
+ require 'action_dispatch'
10
+ end
11
+
12
+ require 'rack-link_headers'
13
+
14
+ class HelperTest < MiniTest::Unit::TestCase
15
+ def setup
16
+ @response = Rack::Response.new
17
+ end
18
+
19
+ def test_link_writes_header
20
+ @response.link 'http://google.com/path?query=5#frag', rel: :search
21
+
22
+ assert_equal '<http://google.com/path?query=5#frag>; rel="search"', @response.headers['Link']
23
+ end
24
+
25
+ def test_multiple_link_writes_header
26
+ @response.link 'http://google.com/path?query=5#frag', rel: :search
27
+ @response.link 'http://test.host/feed.rss', rel: :rss, type: 'application/rss+xml'
28
+
29
+ assert_equal '<http://google.com/path?query=5#frag>; rel="search", <http://test.host/feed.rss>; rel="rss"; type="application/rss+xml"', @response.headers['Link']
30
+ end
31
+
32
+ def test_links
33
+ @response.link 'http://google.com/path?query=5#frag', rel: :search
34
+ @response.link 'http://test.host/feed.rss', rel: :rss, type: 'application/rss+xml'
35
+
36
+ assert_equal @response.links, [{url: 'http://google.com/path?query=5#frag', params: {rel: :search}},
37
+ {url: 'http://test.host/feed.rss', params: {rel: :rss, type: 'application/rss+xml'}}]
38
+ end
39
+
40
+ def test_overrides_manual_headers
41
+ @response.headers['Link'] = 'http://abc.de/'
42
+
43
+ assert_equal 'http://abc.de/', @response.headers['Link']
44
+
45
+ @response.link 'http://google.com/path?query=5#frag', rel: :search
46
+
47
+ assert_equal '<http://google.com/path?query=5#frag>; rel="search"', @response.headers['Link']
48
+ end
49
+
50
+ if ACTIONPACK
51
+ def test_dyn_inject_action_dispatch_response
52
+ assert ActionDispatch::Response.new.respond_to? :link
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,79 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-link_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jan Graichen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
11
+ date: 2020-12-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
- description: Easy Link header management for rack responses.
27
+ description:
31
28
  email:
32
- - jg@altimos.de
29
+ - jgraichen@altimos.de
33
30
  executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .travis.yml
39
- - Gemfile
40
34
  - LICENSE.txt
41
35
  - README.md
42
- - Rakefile
43
36
  - lib/rack-link_headers.rb
44
- - lib/rack/link_headers/header_hash_helper.rb
37
+ - lib/rack/link_headers/helper.rb
45
38
  - lib/rack/link_headers/version.rb
46
39
  - rack-link-headers.gemspec
47
- - test/header_hash_helper_test.rb
40
+ - test/helper_test.rb
48
41
  homepage: ''
49
- licenses: []
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
50
45
  post_install_message:
51
46
  rdoc_options: []
52
47
  require_paths:
53
48
  - lib
54
49
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
50
  requirements:
57
- - - ! '>='
51
+ - - ">="
58
52
  - !ruby/object:Gem::Version
59
53
  version: '0'
60
- segments:
61
- - 0
62
- hash: -121590991522842654
63
54
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
55
  requirements:
66
- - - ! '>='
56
+ - - ">="
67
57
  - !ruby/object:Gem::Version
68
58
  version: '0'
69
- segments:
70
- - 0
71
- hash: -121590991522842654
72
59
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 1.8.24
60
+ rubygems_version: 3.1.2
75
61
  signing_key:
76
- specification_version: 3
62
+ specification_version: 4
77
63
  summary: Easy Link header management for rack responses.
78
64
  test_files:
79
- - test/header_hash_helper_test.rb
65
+ - test/helper_test.rb
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .rbx
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.8.7
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rack-link-headers.gemspec
4
- gemspec
5
-
6
- group :development do
7
- gem 'minitest'
8
- gem 'rake'
9
- end
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs.push "test"
6
- t.test_files = FileList['test/*_test.rb']
7
- t.verbose = true
8
- end
9
-
10
- task :default => :test
@@ -1,30 +0,0 @@
1
- require 'rack/response'
2
-
3
- module Rack
4
- module LinkHeaders
5
- # Helper for easy adding link headers to rack responses.
6
- module HeaderHashHelper
7
- def self.included(base)
8
- base.send :include, InstanceMethods
9
- end
10
-
11
- module InstanceMethods
12
- # Add a new Link header to response headers. Requires
13
- # a rel string and a URL. Does not escape or sanitize
14
- # anything. Manual added Link headers will be
15
- # overridden.
16
- def link(rel, url)
17
- links << {:rel => rel.to_s, :url => url.to_s }
18
- self["Link"] = links.to_a.map{|link| "<#{link[:url]}> rel=\"#{link[:rel]}\""}.join(', ')
19
- end
20
-
21
- def links
22
- @__links ||= []
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- Rack::Response.send :include, Rack::LinkHeaders::HeaderHashHelper
30
- Rack::Response::Helpers.send :include, Rack::LinkHeaders::HeaderHashHelper
@@ -1,40 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require 'rack/response'
4
- require 'rack-link_headers'
5
-
6
- class HeaderHashHelperTest < MiniTest::Unit::TestCase
7
- def setup
8
- @response = Rack::Response.new
9
- end
10
-
11
- def test_link_writes_header
12
- @response.link "search", "http://google.com/path?query=5#frag"
13
-
14
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @response.headers["Link"]
15
- end
16
-
17
- def test_multiple_link_writes_header
18
- @response.link "search", "http://google.com/path?query=5#frag"
19
- @response.link "rss", "http://test.host/feed.rss"
20
-
21
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\", <http://test.host/feed.rss> rel=\"rss\"", @response.headers["Link"]
22
- end
23
-
24
- def test_links
25
- @response.link "search", "http://google.com/path?query=5#frag"
26
- @response.link "rss", "http://test.host/feed.rss"
27
-
28
- assert_equal @response.links, [{:rel=>"search", :url=> "http://google.com/path?query=5#frag"}, {:rel=>"rss", :url=>"http://test.host/feed.rss"}]
29
- end
30
-
31
- def test_overrides_manual_headers
32
- @response.headers["Link"] = "http://abc.de/"
33
-
34
- assert_equal "http://abc.de/", @response.headers["Link"]
35
-
36
- @response.link "search", "http://google.com/path?query=5#frag"
37
-
38
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @response.headers["Link"]
39
- end
40
- end