Class: Hastie::ReportWatcher

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/hastie/report_watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#report_dirObject

Returns the value of attribute report_dir.



13
14
15
# File 'lib/hastie/report_watcher.rb', line 13

def report_dir
  @report_dir
end

Instance Method Details

#check_report_fileObject

this is done just as a double check that we are in a report directory



16
17
18
19
20
21
22
23
24
# File 'lib/hastie/report_watcher.rb', line 16

def check_report_file
  self.report_dir = File.expand_path(path)
  report_config_file = File.join(report_dir, Hastie.report_config_name)
  if !File.exists? report_config_file
    say_status "error","Cannot locate #{Hastie.report_config_name}.", :red
    say_status "error","Directory #{self.report_dir} is not a report.", :red
    exit(1)
  end
end

#read_config_fileObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/hastie/report_watcher.rb', line 30

def read_config_file
  config_file = File.join(self.report_dir, Hastie.watch_config_file)
  if !File.exists? config_file
    say_status "error", "Cannot find #{config_file}", :red
    say_status "error","Directory #{self.report_dir} is not a report.", :red
    exit(1)
  end
  local_config = ConfigFile.load(config_file, :local)
  self.options = local_config.merge(self.options)
end

#set_rootObject



26
27
28
# File 'lib/hastie/report_watcher.rb', line 26

def set_root
  self.destination_root = self.report_dir
end

#start_jekyllObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hastie/report_watcher.rb', line 41

def start_jekyll
  port = self.options["local"]["server_port"] || "4000"
  url = "http://0.0.0.0:#{port}"
  say_status "open", url

  in_root do
    if !File.exist?("config.ru")
      # use built in method
      exec("jekyll --auto --server")
    else
      # use thin method
      jekyllPid = Process.spawn("jekyll --auto")
      thinPid = Process.spawn("thin -p #{port} -R config.ru start")
      trap("INT") {
        [jekyllPid, thinPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
        exit 0
      }

      [jekyllPid, thinPid].each { |pid| Process.wait(pid) }
    end
  end

end