Skip to content

Instantly share code, notes, and snippets.

@na9da
Created December 1, 2010 14:49
Show Gist options
  • Save na9da/723577 to your computer and use it in GitHub Desktop.
Save na9da/723577 to your computer and use it in GitHub Desktop.
Test & patch for async routes with condition clauses
class AsyncTest < Sinatra::Base
register Sinatra::Async
aget '/', :agent => /foo/ do
body "Agent foo"
end
aget '/', :agent => /bar/ do
body "Agent bar"
end
end
AsyncTest.run!
# curl -H'User-agent: bar' http://localhost:4567/
# > Agent bar
# curl -H'User-agent: foo' http://localhost:4567/
# > Agent bar
diff --git a/lib/sinatra/async.rb b/lib/sinatra/async.rb
index 2701fee..cbf900f 100644
--- a/lib/sinatra/async.rb
+++ b/lib/sinatra/async.rb
@@ -59,7 +59,7 @@ module Sinatra #:nodoc:
private
def aroute(verb, path, opts = {}, &block) #:nodoc:
- method = "A#{verb} #{path}".to_sym
+ method = "A#{verb} #{path}#{opts.hash}".to_sym
define_method method, &block
route(verb, path, opts) do |*bargs|
@@ -159,4 +159,4 @@ module Sinatra #:nodoc:
app.helpers Helpers
end
end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment