Method: ATD::App#call
- Defined in:
- lib/atd.rb
#call(env) ⇒ Object
This is the method which responds to .call, as the Rack spec requires. It will return status code 200 and whatever output corresponds the that route if it exists, and if it doesn’t it will return status code 404 and the message “Error 404”
227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/atd.rb', line 227 def call(env) routes = @routes.where(path: env["PATH_INFO"], method: env["REQUEST_METHOD"].downcase.to_sym) warn "WARNING: Multiple routes matched the request" if routes.length > 1 route = routes.first return error 404 if route.nil? output = route.output output = Compilation.compile(route)[:content] unless route.args[:compile] == false return [route.status_code.to_i, Hash(route.headers), Array(output)] if route.block.nil? generate_variables(env, route) return_val = instance_eval(&route.block) if route.block.is_a? Proc return_val = method(route.block).call if route.block.is_a? Method @view[:raw] = return_val if @view[:raw].nil? || @view[:raw].empty? [@status_code.to_i, Hash(@headers), Array(@view[:raw])] end |