module Jeanine::Routing::Evaluation

Public Instance Methods

route_eval() click to toggle source
# File lib/jeanine/routing/evaluation.rb, line 4
def route_eval
  route = find_route
  if route
    result = instance_eval(&route[:block])
    @response.write(result)
  else
    @response.status = 404
  end
  @response.complete!
end

Private Instance Methods

find_route() click to toggle source
# File lib/jeanine/routing/evaluation.rb, line 17
def find_route
  matches = nil
  route = Jeanine.router[@request.request_method.to_sym].detect do |r|
    matches = r[:compiled_path].match(@request.path_info)
    !matches.nil?
  end

  return nil if route.nil?
  return route if route && route[:params].empty?

  index = 0
  while index < matches.captures.size
    param = route[:params][index]
    @request.params[param] = matches.captures[index]
    if index == matches.captures.size
      @request.params[param].gsub!(@request.format)
    end
    index += 1
  end

  route
end