diff --git a/CHANGES b/CHANGES index 18b373e0..3188f699 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ = 1.4.0 / Not Yet Released + * Add support for LINK and UNLINK requests. (Konstantin Haase) + * Add support for Yajl templates. (Jamie Hodge) * Add support for Rabl templates. (Jesse Cooke) diff --git a/README.md b/README.md index 6c44dfa1..84e8c0f1 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,14 @@ end options '/' do .. appease something .. end + +link '/' do + .. affiliate something .. +end + +unlink '/' do + .. separate something .. +end ``` Routes are matched in the order they are defined. The first route that diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index a88b06d3..c91a981d 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -48,7 +48,15 @@ module Sinatra end def idempotent? - safe? or put? or delete? + safe? or put? or delete? or link? or unlink? + end + + def link? + request_method == "LINK" + end + + def unlink? + request_method == "UNLINK" end private @@ -1354,6 +1362,8 @@ module Sinatra def head(path, opts = {}, &bk) route 'HEAD', path, opts, &bk end def options(path, opts = {}, &bk) route 'OPTIONS', path, opts, &bk end def patch(path, opts = {}, &bk) route 'PATCH', path, opts, &bk end + def link(path, opts = {}, &bk) route 'LINK', path, opts, &bk end + def unlink(path, opts = {}, &bk) route 'UNLINK', path, opts, &bk end private def route(verb, path, options = {}, &block) @@ -1860,10 +1870,10 @@ module Sinatra end end - delegate :get, :patch, :put, :post, :delete, :head, :options, :template, :layout, - :before, :after, :error, :not_found, :configure, :set, :mime_type, - :enable, :disable, :use, :development?, :test?, :production?, - :helpers, :settings, :register + delegate :get, :patch, :put, :post, :delete, :head, :options, :link, :unlink, + :template, :layout, :before, :after, :error, :not_found, :configure, + :set, :mime_type, :enable, :disable, :use, :development?, :test?, + :production?, :helpers, :settings, :register class << self attr_accessor :target diff --git a/test/delegator_test.rb b/test/delegator_test.rb index 72ba878d..cdda7b88 100644 --- a/test/delegator_test.rb +++ b/test/delegator_test.rb @@ -60,7 +60,7 @@ class DelegatorTest < Test::Unit::TestCase assert_equal Sinatra::Application, Sinatra::Delegator.target end - %w[get put post delete options patch].each do |verb| + %w[get put post delete options patch link unlink].each do |verb| it "delegates #{verb} correctly" do delegation_app do send(verb, '/hello') { 'Hello World' } diff --git a/test/helper.rb b/test/helper.rb index dc8fd405..1a96710b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -97,6 +97,14 @@ class Test::Unit::TestCase request(uri, env.merge(:method => "PATCH", :params => params), &block) end + def link(uri, params = {}, env = {}, &block) + request(uri, env.merge(:method => "LINK", :params => params), &block) + end + + def unlink(uri, params = {}, env = {}, &block) + request(uri, env.merge(:method => "UNLINK", :params => params), &block) + end + # Delegate other missing methods to response. def method_missing(name, *args, &block) if response && response.respond_to?(name) diff --git a/test/readme_test.rb b/test/readme_test.rb index 26ea0352..3964debb 100644 --- a/test/readme_test.rb +++ b/test/readme_test.rb @@ -22,6 +22,10 @@ class ReadmeTest < Test::Unit::TestCase delete('/') { ".. annihilate something .." } options('/') { ".. appease something .." } + + link('/') { ".. affiliate something .." } + + unlink('/') { ".. separate something .." } end get '/' @@ -41,6 +45,12 @@ class ReadmeTest < Test::Unit::TestCase options '/' assert_body '.. appease something ..' + + link '/' + assert_body '.. affiliate something ..' + + unlink '/' + assert_body '.. separate something ..' end example do diff --git a/test/routing_test.rb b/test/routing_test.rb index 97f98cc0..330db07d 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -23,7 +23,7 @@ class RegexpLookAlike end class RoutingTest < Test::Unit::TestCase - %w[get put post delete options patch].each do |verb| + %w[get put post delete options patch link unlink].each do |verb| it "defines #{verb.upcase} request handlers with #{verb}" do mock_app { send verb, '/hello' do