Class: ArgScanner::Workspace
- Inherits:
-
Object
- Object
- ArgScanner::Workspace
- Defined in:
- lib/arg_scanner/workspace.rb
Instance Method Summary collapse
-
#initialize ⇒ Workspace
constructor
A new instance of Workspace.
- #on_process_exit ⇒ Object
- #on_process_start ⇒ Object
- #open_output_json(prefix) ⇒ Object
Constructor Details
#initialize ⇒ Workspace
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_exit ⇒ Object
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_start ⇒ Object
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 |