rack-link_headers 1.0.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/.gitignore ADDED
@@ -0,0 +1,18 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,9 @@
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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jan Graichen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Rack::LinkHeaders
2
+
3
+ Easy Link header management for rack responses.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-link_headers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-link_headers
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ response.headers.link "rel", "http://abc.de/"
23
+ response.headers.link "rss", "http://test.host/feed.xml"
24
+ ```
25
+ ```
26
+ Link: <http://abc.de/> rel="rel", <http://test.host/feed.xml> rel="rss"
27
+ ```
28
+
29
+ Manual set Link header will be overridden. All links can be
30
+ accessed via `links`:
31
+
32
+ ```ruby
33
+ response.headers.link "rel", "http://abc.de/"
34
+ response.headers.link "rss", "http://test.host/feed.xml"
35
+
36
+ response.headers.links
37
+ # => [{:rel=>"rel", :url=>"http://abc.de/"}, {:rel=>"rss", :url=>"http://test.host/feed.xml"}]
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Add tests for your features.
45
+ 4. Add your features.
46
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 6. Push to the branch (`git push origin my-new-feature`)
48
+ 7. Create new Pull Request
49
+
50
+ ## License
51
+
52
+ [MIT License](http://www.opensource.org/licenses/mit-license.php)
53
+
54
+ Copyright (c) 2013, Jan Graichen
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,29 @@
1
+ require 'rack/utils'
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::Utils::HeaderHash.send :include, Rack::LinkHeaders::HeaderHashHelper
@@ -0,0 +1,14 @@
1
+ module Rack
2
+ module LinkHeaders
3
+ module VERSION
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ PATCH = 0
7
+ STAGE = nil
8
+
9
+ def self.to_s
10
+ [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join '.'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'rack/link_headers/header_hash_helper'
2
+
3
+ module Rack
4
+ module LinkHeaders
5
+ autoload :VERSION, 'rack-link_headers/version'
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'rack/link_headers/version'
6
+
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 = ""
15
+
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"]
20
+
21
+ gem.add_dependency 'rack'
22
+ end
@@ -0,0 +1,40 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'rack/utils'
4
+ require 'rack-link_headers'
5
+
6
+ class HeaderHashHelperTest < MiniTest::Unit::TestCase
7
+ def setup
8
+ @headers = Rack::Utils::HeaderHash.new
9
+ end
10
+
11
+ def test_link_writes_header
12
+ @headers.link "search", "http://google.com/path?query=5#frag"
13
+
14
+ assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @headers["Link"]
15
+ end
16
+
17
+ def test_multiple_link_writes_header
18
+ @headers.link "search", "http://google.com/path?query=5#frag"
19
+ @headers.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\"", @headers["Link"]
22
+ end
23
+
24
+ def test_links
25
+ @headers.link "search", "http://google.com/path?query=5#frag"
26
+ @headers.link "rss", "http://test.host/feed.rss"
27
+
28
+ assert_equal @headers.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
+ @headers["Link"] = "http://abc.de/"
33
+
34
+ assert_equal "http://abc.de/", @headers["Link"]
35
+
36
+ @headers.link "search", "http://google.com/path?query=5#frag"
37
+
38
+ assert_equal "<http://google.com/path?query=5#frag> rel=\"search\"", @headers["Link"]
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-link_headers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Graichen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Easy Link header management for rack responses.
31
+ email:
32
+ - jg@altimos.de
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .travis.yml
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/rack-link_headers.rb
44
+ - lib/rack/link_headers/header_hash_helper.rb
45
+ - lib/rack/link_headers/version.rb
46
+ - rack-link-headers.gemspec
47
+ - test/header_hash_helper_test.rb
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ segments:
61
+ - 0
62
+ hash: -2482873367989671441
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: -2482873367989671441
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Easy Link header management for rack responses.
78
+ test_files:
79
+ - test/header_hash_helper_test.rb