Class: TDiary::Application

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

Instance Method Summary collapse

Constructor Details

#initialize(base_dir = nil) ⇒ Application

Returns a new instance of Application.



18
19
20
21
22
23
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
53
# File 'lib/tdiary/application.rb', line 18

def initialize( base_dir = nil )
	index_path   = self.index_path
	update_path  = self.update_path
	assets_path  = self.assets_path
	assets_paths = self.assets_paths

	base_dir ||= self.base_dir

	@app = ::Rack::Builder.app do
		map base_dir do
			map '/' do
				use TDiary::Rack::HtmlAnchor
				use TDiary::Rack::Static, "public"
				use TDiary::Rack::ValidRequestPath
				map index_path do
					run TDiary::Dispatcher.index
				end
			end

			map update_path do
				use TDiary::Rack::Auth
				run TDiary::Dispatcher.update
			end

			map assets_path do
				environment = Sprockets::Environment.new
				assets_paths.each {|assets_path|
					environment.append_path assets_path
				}

				run environment
			end
		end
	end
	run_plugin_startup_procs
end

Instance Method Details

#assets_pathsObject



65
66
67
68
69
# File 'lib/tdiary/application.rb', line 65

def assets_paths
	TDiary::Extensions::constants.map {|extension|
		TDiary::Extensions::const_get( extension ).assets_path
	}.flatten.uniq
end

#call(env) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/tdiary/application.rb', line 55

def call( env )
	begin
		@app.call( env )
	rescue Exception => e
		body = ["#{e.class}: #{e}\n"]
		body << e.backtrace.join("\n")
		[500, {'Content-Type' => 'text/plain'}, body]
	end
end