Class: TDiary::Server

Inherits:
Object
  • 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.



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

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



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

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

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

	@@server.start
end

.stopObject



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

def stop
	@@server.shutdown
end

Instance Method Details

#shutdownObject



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

def shutdown
	@server.shutdown
end

#startObject



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

def start
	@server.start
end