Class: TestServer::ServerCommands::Rackup

Inherits:
Object
  • Object
show all
Defined in:
lib/test_server/server_commands/rackup.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rackup

Returns a new instance of Rackup.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/test_server/server_commands/rackup.rb', line 12

def initialize(options = {})
  @environment = options.fetch(:environment, :development)
  @pid_file    = options.fetch(:pid_file, TestServer.config.pid_file)
  @config_file = options.fetch(:config_file, ::File.expand_path('../../../../config.ru', __FILE__))
  listen       = options.fetch(:listen, '127.0.0.1:8080')

  begin
    uri = Addressable::URI.heuristic_parse(listen)
  rescue StandardError => e
    fail Exceptions::ServerListenStatementInvalid, "I cannot parse the listen statement: #{listen}. It is invalid: #{e.message}"
  end

  @port        = uri.port
  @host        = uri.host
rescue KeyError => e
  raise ArgumentError, e.message
end

Instance Method Details

#to_sObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/test_server/server_commands/rackup.rb', line 30

def to_s
  cmd = []

  cmd << 'rackup'
  cmd << "-E #{environment}" if environment
  cmd << "-P #{pid_file}" if pid_file
  cmd << "-o #{host}" if host
  cmd << "-p #{port}" if port
  cmd << config_file if config_file

  cmd.join(" ")
end