rack-link_headers 2.1.0 → 2.2.0

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.
data/README.md CHANGED
@@ -19,23 +19,23 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- response.link "rel", "http://abc.de/"
23
- response.link "rss", "http://test.host/feed.xml"
22
+ response.link "http://abc.de/", :rel => :search
23
+ response.link "http://test.host/feed.xml", :rel => :rss, :type => "application/rss+xml"
24
24
  ```
25
25
  ```
26
26
  response.headers["Link"]
27
- # => <http://abc.de/> rel="rel", <http://test.host/feed.xml> rel="rss"
27
+ # => <http://abc.de/>; rel="rel", <http://test.host/feed.xml>; rel="rss"; type="application/rss+xml"
28
28
  ```
29
29
 
30
30
  Manual set Link header will be overridden. All links can be
31
31
  accessed via `links`:
32
32
 
33
33
  ```ruby
34
- response.link "rel", "http://abc.de/"
35
- response.link "rss", "http://test.host/feed.xml"
34
+ response.link "http://abc.de/", :rel => :search
35
+ response.link "http://test.host/feed.xml", :rel => :rss, :type => "application/rss+xml"
36
36
 
37
37
  response.links
38
- # => [{:rel=>"rel", :url=>"http://abc.de/"}, {:rel=>"rss", :url=>"http://test.host/feed.xml"}]
38
+ # => [{:url=>"http://abc.de/", :params=>{:ref=>:search}}, {:url=>"http://test.host/feed.xml", :params=>{:rel=>:rss, :type=>"application/rss+xml"}}]
39
39
  ```
40
40
 
41
41
  ## Contributing
@@ -10,12 +10,17 @@ module Rack
10
10
 
11
11
  module InstanceMethods
12
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
13
+ # a URL and a params hash. Does not escape or
14
+ # sanitize anything. Manual added Link headers will be
15
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(', ')
16
+ def link(url, params = {})
17
+ links << {:url => url.to_s, :params => params}
18
+
19
+ self["Link"] = links.to_a.map do |link|
20
+ "<#{link[:url]}>" + link[:params].to_a.map do |k, v|
21
+ "; #{k}=\"#{v}\""
22
+ end.join
23
+ end.join(', ')
19
24
  end
20
25
 
21
26
  def links
@@ -2,7 +2,7 @@ module Rack
2
2
  module LinkHeaders
3
3
  module VERSION
4
4
  MAJOR = 2
5
- MINOR = 1
5
+ MINOR = 2
6
6
  PATCH = 0
7
7
  STAGE = nil
8
8
 
data/test/helper_test.rb CHANGED
@@ -17,23 +17,24 @@ class HelperTest < MiniTest::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_link_writes_header
20
- @response.link "search", "http://google.com/path?query=5#frag"
20
+ @response.link "http://google.com/path?query=5#frag", :rel => :search
21
21
 
22
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @response.headers["Link"]
22
+ assert_equal "<http://google.com/path?query=5#frag>; rel=\"search\"", @response.headers["Link"]
23
23
  end
24
24
 
25
25
  def test_multiple_link_writes_header
26
- @response.link "search", "http://google.com/path?query=5#frag"
27
- @response.link "rss", "http://test.host/feed.rss"
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
28
 
29
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\", <http://test.host/feed.rss> rel=\"rss\"", @response.headers["Link"]
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
30
  end
31
31
 
32
32
  def test_links
33
- @response.link "search", "http://google.com/path?query=5#frag"
34
- @response.link "rss", "http://test.host/feed.rss"
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
35
 
36
- assert_equal @response.links, [{:rel=>"search", :url=> "http://google.com/path?query=5#frag"}, {:rel=>"rss", :url=>"http://test.host/feed.rss"}]
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"}}]
37
38
  end
38
39
 
39
40
  def test_overrides_manual_headers
@@ -41,9 +42,9 @@ class HelperTest < MiniTest::Unit::TestCase
41
42
 
42
43
  assert_equal "http://abc.de/", @response.headers["Link"]
43
44
 
44
- @response.link "search", "http://google.com/path?query=5#frag"
45
+ @response.link "http://google.com/path?query=5#frag", :rel => :search
45
46
 
46
- assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @response.headers["Link"]
47
+ assert_equal "<http://google.com/path?query=5#frag>; rel=\"search\"", @response.headers["Link"]
47
48
  end
48
49
 
49
50
  if ENV["GEM"].to_s.include?('ad')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-link_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  segments:
61
61
  - 0
62
- hash: -3994897237737635876
62
+ hash: -3911852956380959271
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  segments:
70
70
  - 0
71
- hash: -3994897237737635876
71
+ hash: -3911852956380959271
72
72
  requirements: []
73
73
  rubyforge_project:
74
74
  rubygems_version: 1.8.24