Class: SimpleServer::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd, port = 3000) ⇒ Server

Returns a new instance of Server.



12
13
14
15
# File 'lib/simple_server.rb', line 12

def initialize root = Dir.pwd, port = 3000
  self.root = root
  self.port = port
end

Instance Attribute Details

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/simple_server.rb', line 9

def port
  @port
end

#rootObject

Returns the value of attribute root.



6
7
8
# File 'lib/simple_server.rb', line 6

def root
  @root
end

Instance Method Details

#runObject



21
22
23
24
# File 'lib/simple_server.rb', line 21

def run
  trap("INT") { server.shutdown }
  server.start
end

#serverObject



17
18
19
# File 'lib/simple_server.rb', line 17

def server
  @server ||= WEBrick::HTTPServer.new(:Port => port, :DocumentRoot => root)
end