Class: Rity::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rity/cli.rb

Instance Method Summary collapse

Instance Method Details

#startObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rity/cli.rb', line 30

def start
  address = options[:bind] || "127.0.0.1"
  port = options[:port] || 3000
  
  rackup = options[:rackup] || "config.ru"
  app = Rack::Builder.parse_file(rackup)[0]
  
  unless options[:quiet]
    log = Logger.new($stderr)
    log.formatter = proc do |severity, time, progname, message|
      "[#{time}] #{severity}: #{message}\n"
    end
    
    log.info("Binding to #{address}:#{port}")
  end
  
  EM.synchrony do
    trap("INT") { EM.stop }
    trap("TERM") { EM.stop }
    
    EM.epoll
    
    EM.start_server address, port, Connection do |conn|
      conn.app = app
      conn.log = log if defined? log
    end
  end
end

#versionObject



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

def version
  say Rity::VERSION
end