Class: Uki::Server
- Inherits:
-
Object
- Object
- Uki::Server
- Defined in:
- lib/uki/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Host string.
-
#port ⇒ Object
readonly
Port number.
Instance Method Summary collapse
-
#initialize(hoststr) ⇒ Server
constructor
A new instance of Server.
- #start! ⇒ Object
Constructor Details
#initialize(hoststr) ⇒ Server
Returns a new instance of Server.
16 17 18 19 |
# File 'lib/uki/server.rb', line 16 def initialize hoststr @host, @port = (hoststr || 'localhost').split(':') @port ||= 21119 # 21 u, 11 k, 9 i end |
Instance Attribute Details
#host ⇒ Object (readonly)
Host string.
8 9 10 |
# File 'lib/uki/server.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Port number.
13 14 15 |
# File 'lib/uki/server.rb', line 13 def port @port end |
Instance Method Details
#start! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/uki/server.rb', line 21 def start! host, port = @host, @port # otherwise sinatra host and port will hide Server methods Sinatra::Application.class_eval do begin $stderr.puts 'Started uki server at http://%s:%d' % [host, port.to_i] detect_rack_handler.run self, :Host => host, :Port => port do |server| trap 'INT' do server.respond_to?(:stop!) ? server.stop! : server.stop end end rescue Errno::EADDRINUSE raise "Port #{port} already in use" rescue Errno::EACCES raise "Permission Denied on port #{port}" end end end |