Class: ZygoteServer

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

Instance Method Summary collapse

Constructor Details

#initialize(port: 7000, threads: 1000, host: '0.0.0.0', config_path: nil, cells: [], debug: false) ⇒ ZygoteServer

Returns a new instance of ZygoteServer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zygote/server.rb', line 5

def initialize(port: 7000, threads:1000, host: '0.0.0.0', config_path: nil, cells: [], debug:false)
  debug ||= ENV['DEBUG']

  cell_config = YAML.load(File.read(config_path || File.join(Dir.pwd, 'config', 'cells.yml')))
  ZygoteWeb.views = [File.expand_path('../../../views', __FILE__), cells].flatten
  ZygoteWeb.cell_config = cell_config
  if debug
    $stdout.sync = true
    $stderr.sync = true
  end

  app = ZygoteWeb.new
  dispatch = Rack::Builder.app do
    map '/' do
      run app
    end
  end
  Thin::Logging.trace=true if debug
  @server = Thin::Server.new(port, host, dispatch, threadpool_size: threads).backend
end

Instance Method Details

#runObject



33
34
35
36
37
38
# File 'lib/zygote/server.rb', line 33

def run
  EM.run do
    init_sighandlers
    @server.start
  end
end

#startObject



26
27
28
29
30
31
# File 'lib/zygote/server.rb', line 26

def start
  @server.start
rescue => ex
  puts ex
  puts ex.backtrace.join("\n")
end