Class: Rack::Multiplexer
- Inherits:
-
Object
- Object
- Rack::Multiplexer
- Defined in:
- lib/rack/multiplexer.rb,
lib/rack/multiplexer/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.8"
Instance Method Summary collapse
- #any(pattern, application, &block) ⇒ Object
- #append(method, pattern, application) ⇒ Object
- #call(env) ⇒ Object
- #delete(pattern, application = nil, &block) ⇒ Object
- #get(pattern, application = nil, &block) ⇒ Object
-
#initialize(not_found_application = nil, &block) ⇒ Multiplexer
constructor
A new instance of Multiplexer.
- #not_found_application ⇒ Object
- #patch(pattern, application = nil, &block) ⇒ Object
- #post(pattern, application = nil, &block) ⇒ Object
- #put(pattern, application = nil, &block) ⇒ Object
- #routes ⇒ Object
Constructor Details
#initialize(not_found_application = nil, &block) ⇒ Multiplexer
Returns a new instance of Multiplexer.
19 20 21 22 |
# File 'lib/rack/multiplexer.rb', line 19 def initialize(not_found_application = nil, &block) @not_found_application = not_found_application instance_eval(&block) if block end |
Instance Method Details
#any(pattern, application, &block) ⇒ Object
53 54 55 |
# File 'lib/rack/multiplexer.rb', line 53 def any(pattern, application, &block) append("ANY", pattern, application || block) end |
#append(method, pattern, application) ⇒ Object
57 58 59 |
# File 'lib/rack/multiplexer.rb', line 57 def append(method, pattern, application) routes[method] << Route.new(pattern, application) end |
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rack/multiplexer.rb', line 24 def call(env) path = env["PATH_INFO"] ( routes[env["REQUEST_METHOD"]].find(path) || routes["ANY"].find(path) || not_found_application ).call(env) end |
#delete(pattern, application = nil, &block) ⇒ Object
49 50 51 |
# File 'lib/rack/multiplexer.rb', line 49 def delete(pattern, application = nil, &block) append("DELETE", pattern, application || block) end |
#get(pattern, application = nil, &block) ⇒ Object
33 34 35 |
# File 'lib/rack/multiplexer.rb', line 33 def get(pattern, application = nil, &block) append("GET", pattern, application || block) end |
#not_found_application ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rack/multiplexer.rb', line 65 def not_found_application @not_found_application ||= ->(env) { [ 404, { "Content-Type" => "text/plain", "Content-Length" => "0", }, [""], ] } end |
#patch(pattern, application = nil, &block) ⇒ Object
45 46 47 |
# File 'lib/rack/multiplexer.rb', line 45 def patch(pattern, application = nil, &block) append("PATCH", pattern, application || block) end |
#post(pattern, application = nil, &block) ⇒ Object
37 38 39 |
# File 'lib/rack/multiplexer.rb', line 37 def post(pattern, application = nil, &block) append("POST", pattern, application || block) end |
#put(pattern, application = nil, &block) ⇒ Object
41 42 43 |
# File 'lib/rack/multiplexer.rb', line 41 def put(pattern, application = nil, &block) append("PUT", pattern, application || block) end |