Module: ParallelReportPortal::FileUtils
- Included in:
- ParallelReportPortal
- Defined in:
- lib/parallel_report_portal/file_utils.rb
Overview
Common file handling methods
Instance Method Summary collapse
-
#delete_file(filename) ⇒ Object
Helper for deleting a file.
-
#file_open_exlock_and_block(filename, mode) {|file| ... } ⇒ Object
Open a file with an exclusive lock and yield the open file to the block.
-
#hierarchy_file ⇒ Pathname
Returns a pathname for the hierarchy of this launch, initialising if necesssary.
-
#launch_id_file ⇒ Pathname
Returns a pathname for the pid for this launch, initialising if necesssary.
-
#parallel? ⇒ Boolean
Attempts to determin if the current environment is running under a parallel testing environment.
-
#pid ⇒ Integer
Gets the pid of this process or the parent pid if running in parallel mode.
Instance Method Details
#delete_file(filename) ⇒ Object
Helper for deleting a file. It will not throw an exception if the file does not exist.
57 58 59 |
# File 'lib/parallel_report_portal/file_utils.rb', line 57 def delete_file(filename) File.delete(filename) if File.exist?(filename) end |
#file_open_exlock_and_block(filename, mode) {|file| ... } ⇒ Object
Open a file with an exclusive lock and yield the open file to the block. If the system is unable to access the file it will block until the lock is removed. This method guarantees that the lock will be removed.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/parallel_report_portal/file_utils.rb', line 13 def file_open_exlock_and_block(filename, mode, &block) file = File.new(filename, mode) begin file.flock(File::LOCK_EX) yield(file) if block_given? ensure file.flock(File::LOCK_UN) file.close end end |
#hierarchy_file ⇒ Pathname
Returns a pathname for the hierarchy of this launch, initialising if necesssary.
42 43 44 |
# File 'lib/parallel_report_portal/file_utils.rb', line 42 def hierarchy_file @hierarchy_file ||= Pathname(Dir.tmpdir) + ("report_portal_hierarchy_file_#{pid}.lck") end |
#launch_id_file ⇒ Pathname
Returns a pathname for the pid for this launch, initialising if necesssary.
35 36 37 |
# File 'lib/parallel_report_portal/file_utils.rb', line 35 def launch_id_file @lock_file ||= Pathname(Dir.tmpdir) + ("report_portal_tracking_file_#{pid}.lck") end |
#parallel? ⇒ Boolean
Attempts to determin if the current environment is running under a parallel testing environment
28 29 30 |
# File 'lib/parallel_report_portal/file_utils.rb', line 28 def parallel? !ENV['PARALLEL_PID_FILE'].nil? end |
#pid ⇒ Integer
Gets the pid of this process or the parent pid if running in parallel mode.
49 50 51 |
# File 'lib/parallel_report_portal/file_utils.rb', line 49 def pid pid = parallel? ? Process.ppid : Process.pid end |