Module: Harvixture::Command

Defined in:
lib/harvixture/command.rb

Class Method Summary collapse

Class Method Details

.process!(options = {}) ⇒ Object

:rails_root :output_dir :request_path :rails_env :user_id



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/harvixture/command.rb', line 10

def process!(options={})
  process = nil
  Preparer.do_it!(options[:rails_root])
  Config.update(options)
  process = Process.fork do
    Signal.trap('HUP') { exit }
    stdin = open '/dev/null', 'r'
    stdout = open '/dev/null', 'w'
    stderr = open '/dev/null', 'w'
    STDIN.reopen stdin
    STDOUT.reopen stdout
    STDERR.reopen stderr
    exec %(ruby script/server -e harvixture -p 8675)
  end
  # Wait for the script server to reload
  sleep(5)
  open(File.join('http://localhost:8675', Config.request_path))
rescue Exception => e
  puts e
  puts e.backtrace
ensure
  Process.kill('HUP', process) if process
  Process.wait
  Process.exit!
end