mirror of
				https://github.com/sinatra/sinatra
				synced 2023-03-27 23:18:01 -04:00 
			
		
		
		
	add support for LINK and UNLINK requests
This commit is contained in:
		
							parent
							
								
									be1df6209a
								
							
						
					
					
						commit
						82009d446f
					
				
					 7 changed files with 45 additions and 7 deletions
				
			
		
							
								
								
									
										2
									
								
								CHANGES
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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' }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue