Class: Mack::Runner

Inherits:
Object
  • Object
show all
Includes:
Mack::Routes::Urls
Defined in:
lib/mack.rb

Overview

This is the heart and soul of the Mack framework! This class interfaces with the Rack framework. It handles all the dispatching back and forth between the Rack framework and a Mack application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mack::Routes::Urls

#droute_url, #redirect_html, #url_for_pattern

Instance Attribute Details

#cookiesObject (readonly)

:nodoc:



11
12
13
# File 'lib/mack.rb', line 11

def cookies
  @cookies
end

#requestObject (readonly)

:nodoc:



10
11
12
# File 'lib/mack.rb', line 10

def request
  @request
end

#responseObject (readonly)

:nodoc:



9
10
11
# File 'lib/mack.rb', line 9

def response
  @response
end

Instance Method Details

#call(env) ⇒ Object

This method needs to be defined as part of the Rack framework. As is noted for the Mack::Runner class, this is where the center of the Mack framework lies.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mack.rb', line 14

def call(env)
  # pp env
  begin
    setup(env) do
      begin
        route = Mack::Routes::RouteMap.instance.get_route_from_request(self.request)
        if route[:redirect_to]
          # because the route is specified to be a redirect, let's do that:
          redirect_to(route)
        else
          # let's handle a normal request:
          c = "#{route[:controller].to_s.camelcase}Controller".constantize.new(self.request, self.response, self.cookies)
          self.response.controller = c
          self.response.write(c.run)
        end
      rescue Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute => e
        return try_to_find_resource(env, self.request.path_info, e)
      end
    end # setup
  rescue Exception => e
    MACK_DEFAULT_LOGGER.error(e)
    raise e
  end
end