Class: HK::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/hotchkiss/application.rb

Constant Summary collapse

@@router =
nil
@@root =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#rootObject

Returns the value of attribute root.



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

def root
  @root
end

#routerObject

Returns the value of attribute router.



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

def router
  @router
end

Class Method Details

.burnbabyburn!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hotchkiss/application.rb', line 24

def self.burnbabyburn!
  lambda do |env|
    begin
      route, params = @@router.match?(env)
      env['hk.params'] = (params.nil? ? {} : params)
      if !route.nil? && route.has_key?(:special)
        env['hk.controller'] = route[:controller]
      elsif !route.nil?
        env['hk.controller'] = "#{route[:controller].capitalize}Controller"
      else
        raise Exception, "Unknown route for path: #{env['REQUEST_PATH']}"
      end
      env['hk.action'] = route[:action]
      resp = Object.const_get(env['hk.controller']).new.call(env)
    rescue Exception => e
      env['hk.action'] = "on_exception"
      env['hk.exception'] = e
      if Object.const_get("ApplicationController").instance_methods(false).include?(:on_exception)
        env['hk.controller'] = :ApplicationController
      else
        env['hk.controller'] = :FastResponder
      end
      resp = Object.const_get(env['hk.controller']).new.call(env)
    end
    response = Rack::Response.new()
    response.write(resp)
    response.finish
  end
end

.rootObject



20
21
22
# File 'lib/hotchkiss/application.rb', line 20

def self.root
  @@root
end

.root=(root) ⇒ Object



16
17
18
# File 'lib/hotchkiss/application.rb', line 16

def self.root=(root)
  @@root = root if @@root.nil?
end

.router=(router) ⇒ Object



12
13
14
# File 'lib/hotchkiss/application.rb', line 12

def self.router=(router)
  @@router = router if @@router.nil?
end