Class: Yogo::Rack::ModelLookup
- Inherits:
-
Object
- Object
- Yogo::Rack::ModelLookup
- Defined in:
- lib/yogo/rack/model_lookup.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ModelLookup
constructor
A new instance of ModelLookup.
Constructor Details
#initialize(app, options = {}) ⇒ ModelLookup
Returns a new instance of ModelLookup.
8 9 10 11 12 13 |
# File 'lib/yogo/rack/model_lookup.rb', line 8 def initialize(app, = {}) paths = [:paths] || ['data'] @app = app @scope = [:scope] || lambda { |*args| return Schema } @base_regexp = /^\/(#{paths.join('|')})\/((\w|-|\s)+)/ end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/yogo/rack/model_lookup.rb', line 15 def call(env) if env['PATH_INFO'] =~ @base_regexp model_id = $2 env['yogo.schema'], env['yogo.resource'] = get_model(model_id, env) return [ 404, {'Content-Type' => 'text/plain'}, ["#{model_id} not found"] ] if env['yogo.schema'].nil? end @app.call(env) end |