class RackStep::App

Abstract class with the base of a RackStep app. This class MUST be extended by the user.

Attributes

request[R]

Stores the received request which will then be injected into the user controllers.

Public Class Methods

add_route(verb, path, controller) click to toggle source

This method was created to make it easier for the user to add routes, but it will delegate to the router singleton class.

# File lib/rackstep.rb, line 63
def self.add_route(verb, path, controller)
  router = Router.instance
  router.add_route(verb, path, controller)
end
call(env) click to toggle source

Static method called from config.ru (“run App”).

# File lib/rackstep.rb, line 29
def self.call(env)
  response = new(env).process_request
  return response.status, response.headers, response.body
end
new(env) click to toggle source

Initialize the request instance variable and add a default “not found” route.

# File lib/rackstep.rb, line 35
def initialize(env)
  @request = Rack::Request.new(env)

  # Adding default routes to handle page not found (404).
  router.add_route_for_all_verbs('notfound', RackStep::NotFoundController)
end

Public Instance Methods

process_request() click to toggle source

TODO: Code Climate says this method is too big.

# File lib/rackstep.rb, line 43
def process_request
  verb = request.request_method
  path = request.path

  # In RackStep, each request is processed by a controller. The router
  # is responsable to find, based on the given path and http verb,
  # the apropriate controller to handle the request.
  route = router.find_route_for(path, verb)
  controller = route.controller.new
  controller.request = request
  controller.send(:before)
  controller.send(:process_request)
  controller.send(:after)
  response = controller.response

  return response
end
router() click to toggle source

Access the Router, a singleton class that stores all the registred routes.

# File lib/rackstep.rb, line 24
def router
  Router.instance
end