Class: BackendAPI
- Inherits:
-
Object
- Object
- BackendAPI
- Defined in:
- lib/backend_api.rb
Constant Summary collapse
- VERSION =
[0,3,4]
- WRAP =
<<-EOT <!doctype html> <html> <head><meta charset="UTF-8" /><title>%s</title></head> <body> %s </body> </html> EOT
Class Method Summary collapse
-
.new ⇒ Object
Automatically use MethodOverride before Thx Konstantin Haase for the trick.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(app = nil) ⇒ BackendAPI
constructor
A new instance of BackendAPI.
Constructor Details
#initialize(app = nil) ⇒ BackendAPI
Returns a new instance of BackendAPI.
16 |
# File 'lib/backend_api.rb', line 16 def initialize(app=nil); @app = app; end |
Class Method Details
.new ⇒ Object
Automatically use MethodOverride before Thx Konstantin Haase for the trick
15 |
# File 'lib/backend_api.rb', line 15 def self.new(*); ::Rack::MethodOverride.new(super); end |
Instance Method Details
#call(env) ⇒ Object
17 |
# File 'lib/backend_api.rb', line 17 def call(env); dup.call!(env); end |
#call!(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/backend_api.rb', line 19 def call!(env) @req = ::Rack::Request.new(env) @res = ::Rack::Response.new # Simple dispatcher @model_name, @id, *a = @req.path_info.split('/').find_all{|s| s!=''} # Special case return @res.finish{@res.write(v)} if @model_name=='_version' build_model_vars __send__(@req.request_method.downcase) unless @res.status==404 @res.status==404&&!@app.nil? ? @app.call(env) : @res.finish end |