Class: Rack::JSON::Resource
- Inherits:
-
Object
- Object
- Rack::JSON::Resource
- Includes:
- EndPoint
- Defined in:
- lib/rackjson/resource.rb
Constant Summary collapse
- HTTP_METHODS =
[:get, :post, :put, :delete, :options]
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(app, options) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 |
# File 'lib/rackjson/resource.rb', line 6 def initialize(app, ) @app = app @collections = [:collections] @db = [:db] @methods = [:only] || HTTP_METHODS - ([:except] || []) end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rackjson/resource.rb', line 13 def call(env) request = Rack::JSON::Request.new(env) if bypass? request @app.call(env) elsif method_not_allowed? request render "", :status => 405 else @collection = Rack::JSON::Collection.new(@db[request.collection]) send(request.request_method.downcase, request) end end |