Class: TDiary::Server

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Server

Returns a new instance of Server.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tdiary/server.rb', line 31

def initialize( opts )
	@server = WEBrick::HTTPServer.new(
		:Port => opts[:port], BindAddress: opts[:bind],
		:DocumentRoot => TDiary.root,
		:MimeTypes => tdiary_mime_types,
		:Logger => webrick_logger_to( opts[:logger] ),
		:AccessLog => webrick_access_log_to( opts[:access_log] ),
		:ServerType => opts[:daemon] ? WEBrick::Daemon : nil,
		:CGIInterpreter => WEBrick::HTTPServlet::CGIHandler::Ruby
	)
	@server.logger.level = WEBrick::Log::DEBUG
	@server.mount("/", WEBrick::HTTPServlet::CGIHandler, TDiary.root + "/index.rb")
	@server.mount("/index.rb", WEBrick::HTTPServlet::CGIHandler, TDiary.root + '/index.rb')
	@server.mount("/update.rb", WEBrick::HTTPServlet::CGIHandler, TDiary.root + "/update.rb")
	@server.mount("/theme", WEBrick::HTTPServlet::FileHandler, TDiary.root + '/theme')
	@server.mount("/js", WEBrick::HTTPServlet::FileHandler, TDiary.root + '/js')
end

Class Method Details

.run(option) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/tdiary/server.rb', line 17

def run( option )
	@@server = new( option )

	trap( "INT" ) { @@server.shutdown }
	trap( "TERM" ) { @@server.shutdown }

	@@server.start
end

.stopObject



26
27
28
# File 'lib/tdiary/server.rb', line 26

def stop
	@@server.shutdown
end

Instance Method Details

#shutdownObject



53
54
55
# File 'lib/tdiary/server.rb', line 53

def shutdown
	@server.shutdown
end

#startObject



49
50
51
# File 'lib/tdiary/server.rb', line 49

def start
	@server.start
end