Class: Reifier::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Server

Returns a new instance of Server.



3
4
5
6
# File 'lib/reifier/server.rb', line 3

def initialize(app, options = {})
  @app     = app
  @options = options
end

Instance Method Details

#load_configurationObject



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

def load_configuration
  if defined?(Rails)
    path = Rails.root.join('config/reifier.rb')
  else
    path = Dir.pwd + '/reifier.rb'
  end

  return unless File.exist?(path)

  lines = File.read(path).split("\n")

  lines.each do |line|
    eval(line)
  end

  puts "======= Loaded settings from #{path} =======\n"
rescue NoMethodError => e
  raise UnsupportedOptionError, "Option #{e.name} is not supported from config file"
end

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/reifier/server.rb', line 28

def start
  server = TCPServer.new(@options[:Host], @options[:Port])

  puts "# Ruby version: #{RUBY_VERSION}"
  puts "# Min threads: #{@options[:MinThreads]}, max threads: #{@options[:MaxThreads]}"
  puts "# Environment: #{@options[:environment]}"
  puts "# Master PID: #{Process.pid}"
  puts "# Listening on tcp://#{server.addr.last}:#{@options[:Port]}"

  if @options[:Workers]
    start_clustered(server)
  else
    start_single(server)
  end
end