Class: Zygote::Server

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

Overview

Wrapper around thin / event machine to run zygote sinatra rack app in.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Server.



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

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')))
  Zygote::Web.views = [File.expand_path('../../../views', __FILE__), cells].flatten
  Zygote::Web.cell_config = cell_config
  if debug
    $stdout.sync = true
    $stderr.sync = true
  end

  app = Zygote::Web.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



36
37
38
39
40
41
# File 'lib/zygote/server.rb', line 36

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

#startObject



29
30
31
32
33
34
# File 'lib/zygote/server.rb', line 29

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