public
Rubygem
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/bmizerany/sinatra.git
capture agent captures in params
Blake Mizerany (author)
Mon Mar 24 18:04:51 -0700 2008
commit  0b485a96a3dca775e9011e19698af11b58b43e8b
tree    ca419209d5033813c436b27ba0faeaa44e2addbf
parent  1f204991c34fa36f0a678c10019ba065579bd081
...
145
146
147
 
148
149
 
150
151
152
 
153
154
155
...
145
146
147
148
149
150
151
152
153
 
154
155
156
157
0
@@ -145,11 +145,13 @@ module Sinatra
0
     end
0
         
0
     def invoke(request)
0
+ params = {}
0
       if options[:agent]
0
         return unless request.user_agent =~ options[:agent]
0
+ params[:agent] = $~[1..-1]
0
       end
0
       return unless pattern =~ request.path_info.squeeze('/')
0
- params = param_keys.zip($~.captures.map(&:from_param)).to_hash
0
+ params.merge!(param_keys.zip($~.captures.map(&:from_param)).to_hash)
0
       Result.new(block, params, 200)
0
     end
0
     
...
142
143
144
 
 
 
 
 
 
 
 
 
 
 
 
145
146
147
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
0
@@ -142,6 +142,18 @@ context "Events in an app" do
0
     should.not.be.ok
0
 
0
   end
0
+
0
+ specify "can filters by agent" do
0
+
0
+ get '/', :agent => /Windows (NT)/ do
0
+ params[:agent].first
0
+ end
0
+
0
+ get_it '/', :agent => 'Windows NT'
0
+
0
+ body.should.equal 'NT'
0
+
0
+ end
0
   
0
 end
0
 

Comments

    No one has commented yet.