Class: Rack::Builder
- Inherits:
-
Object
- Object
- Rack::Builder
- Defined in:
- lib/ext/rack/rack_mapper.rb
Overview
Replacement for Builder which using HttpRouter to map requests instead of a simple Hash. As well, add convenience methods for the request methods.
Instance Method Summary collapse
-
#delete(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘DELETE` to a block.
-
#get(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘HEAD` and `GET` to a block.
-
#head(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘HEAD` to a block.
-
#initialize(&block) ⇒ Builder
constructor
A new instance of Builder.
-
#map(path, options = nil, &block) ⇒ Object
Maps a path to a block.
-
#post(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘POST` to a block.
-
#put(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘PUT` to a block.
- #router ⇒ Object
Constructor Details
#initialize(&block) ⇒ Builder
Returns a new instance of Builder.
4 5 6 |
# File 'lib/ext/rack/rack_mapper.rb', line 4 def initialize(&block) super end |
Instance Method Details
#delete(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘DELETE` to a block.
49 50 51 |
# File 'lib/ext/rack/rack_mapper.rb', line 49 def delete(path, = nil, &block) router.delete(path).().to(&block) end |
#get(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘HEAD` and `GET` to a block.
25 26 27 |
# File 'lib/ext/rack/rack_mapper.rb', line 25 def get(path, = nil, &block) router.get(path).().to(&block) end |
#head(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘HEAD` to a block.
57 58 59 |
# File 'lib/ext/rack/rack_mapper.rb', line 57 def head(path, = nil, &block) router.head(path).().to(&block) end |
#map(path, options = nil, &block) ⇒ Object
Maps a path to a block.
16 17 18 19 |
# File 'lib/ext/rack/rack_mapper.rb', line 16 def map(path, = nil, &block) router.add(path).().to(&block) @ins << router unless @ins.last == router end |
#post(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘POST` to a block.
33 34 35 |
# File 'lib/ext/rack/rack_mapper.rb', line 33 def post(path, = nil, &block) router.post(path).().to(&block) end |
#put(path, options = nil, &block) ⇒ Object
Maps a path with request methods ‘PUT` to a block.
41 42 43 |
# File 'lib/ext/rack/rack_mapper.rb', line 41 def put(path, = nil, &block) router.put(path).().to(&block) end |
#router ⇒ Object
8 9 10 |
# File 'lib/ext/rack/rack_mapper.rb', line 8 def router @router ||= HttpRouter.new end |