Class: Uki::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

Host string.



8
9
10
# File 'lib/uki/server.rb', line 8

def host
  @host
end

#portObject (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