aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-11-29 17:45:12 -0600
committerJoshua Peek <josh@joshpeek.com>2009-11-29 17:45:12 -0600
commitf69f9820ee84f32bb53d001efd6ebc79517fb0e1 (patch)
treea7f0eb2939db8f04b74c4e3c44363f7e9f5ba966 /actionpack/lib
parent312c3bfa247249a1562eb9d04c335f4d38a18b28 (diff)
downloadrails-f69f9820ee84f32bb53d001efd6ebc79517fb0e1.tar.gz
rails-f69f9820ee84f32bb53d001efd6ebc79517fb0e1.tar.bz2
rails-f69f9820ee84f32bb53d001efd6ebc79517fb0e1.zip
Wrap up http related routing helpers
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb70
1 files changed, 37 insertions, 33 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 57bbb55c1c..8dfac30ac0 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -264,6 +264,42 @@ module ActionDispatch
end
end
+ module HttpHelpers
+ def get(*args, &block)
+ map_method(:get, *args, &block)
+ end
+
+ def post(*args, &block)
+ map_method(:post, *args, &block)
+ end
+
+ def put(*args, &block)
+ map_method(:put, *args, &block)
+ end
+
+ def delete(*args, &block)
+ map_method(:delete, *args, &block)
+ end
+
+ def redirect(path, options = {})
+ status = options[:status] || 301
+ lambda { |env|
+ req = Rack::Request.new(env)
+ url = req.scheme + '://' + req.host + path
+ [status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
+ }
+ end
+
+ private
+ def map_method(method, *args, &block)
+ options = args.extract_options!
+ options[:via] = method
+ args.push(options)
+ match(*args, &block)
+ self
+ end
+ end
+
class Constraints
def new(app, constraints = [])
if constraints.any?
@@ -295,26 +331,11 @@ module ActionDispatch
def initialize(set)
@set = set
+ extend HttpHelpers
extend Scoping
extend Resources
end
- def get(*args, &block)
- map_method(:get, *args, &block)
- end
-
- def post(*args, &block)
- map_method(:post, *args, &block)
- end
-
- def put(*args, &block)
- map_method(:put, *args, &block)
- end
-
- def delete(*args, &block)
- map_method(:delete, *args, &block)
- end
-
def root(options = {})
match '/', options.merge(:as => :root)
end
@@ -375,15 +396,6 @@ module ActionDispatch
self
end
- def redirect(path, options = {})
- status = options[:status] || 301
- lambda { |env|
- req = Rack::Request.new(env)
- url = req.scheme + '://' + req.host + path
- [status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
- }
- end
-
private
def initialize_app_endpoint(options, defaults)
app = nil
@@ -412,14 +424,6 @@ module ActionDispatch
raise ArgumentError, "missing :action"
end
end
-
- def map_method(method, *args, &block)
- options = args.extract_options!
- options[:via] = method
- args.push(options)
- match(*args, &block)
- self
- end
end
end
end