Class: TDiary::Server

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

Defined Under Namespace

Modules: CGIEnvironment Classes: CGIHandler

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Server

Returns a new instance of Server.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tdiary/server.rb', line 52

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("/", CGIHandler, TDiary.root + "/index.rb")
  @server.mount("/index.rb", CGIHandler, TDiary.root + '/index.rb')
  @server.mount("/update.rb", 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



38
39
40
41
42
43
44
45
# File 'lib/tdiary/server.rb', line 38

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

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

  @@server.start
end

.stopObject



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

def stop
  @@server.shutdown
end

Instance Method Details

#shutdownObject



74
75
76
# File 'lib/tdiary/server.rb', line 74

def shutdown
  @server.shutdown
end

#startObject



70
71
72
# File 'lib/tdiary/server.rb', line 70

def start
  @server.start
end