Class: ArgScanner::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/arg_scanner/workspace.rb

Instance Method Summary collapse

Constructor Details

#initializeWorkspace

Returns a new instance of Workspace.



4
5
6
7
# File 'lib/arg_scanner/workspace.rb', line 4

def initialize
  @dir = ENV["ARG_SCANNER_DIR"] || "."
  @pid_file = @dir+"/#{Process.pid}.pid"
end

Instance Method Details

#on_process_exitObject



22
23
24
25
# File 'lib/arg_scanner/workspace.rb', line 22

def on_process_exit
  require 'fileutils'
  FileUtils.rm(@pid_file)
end

#on_process_startObject



9
10
11
# File 'lib/arg_scanner/workspace.rb', line 9

def on_process_start
  File.open(@pid_file, "w") {}
end

#open_output_json(prefix) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/arg_scanner/workspace.rb', line 14

def open_output_json(prefix)
  path = @dir + "/#{prefix}-#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}-#{Process.pid}.json"
  path_tmp_name = path + ".temp"
  File.open(path_tmp_name, "w") { |file| yield file }
  require 'fileutils'
  FileUtils.mv(path_tmp_name, path)
end