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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tdiary/application.rb', line 9

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
				run TDiary::Rack::Static.new(nil, assets_paths)
			end
		end
	end
	run_plugin_startup_procs
end

Instance Method Details

#assets_pathsObject



51
52
53
54
55
# File 'lib/tdiary/application.rb', line 51

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

#call(env) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tdiary/application.rb', line 41

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