class ParallelTests::Pids
Attributes
file_path[R]
mutex[R]
Public Class Methods
new(file_path)
click to toggle source
# File lib/parallel_tests/pids.rb, line 7 def initialize(file_path) @file_path = file_path @mutex = Mutex.new end
Public Instance Methods
add(pid)
click to toggle source
# File lib/parallel_tests/pids.rb, line 12 def add(pid) pids << pid.to_i save end
all()
click to toggle source
# File lib/parallel_tests/pids.rb, line 27 def all read pids end
count()
click to toggle source
# File lib/parallel_tests/pids.rb, line 22 def count read pids.count end
delete(pid)
click to toggle source
# File lib/parallel_tests/pids.rb, line 17 def delete(pid) pids.delete(pid.to_i) save end
Private Instance Methods
clear()
click to toggle source
# File lib/parallel_tests/pids.rb, line 38 def clear @pids = [] save end
pids()
click to toggle source
# File lib/parallel_tests/pids.rb, line 34 def pids @pids ||= [] end
read()
click to toggle source
# File lib/parallel_tests/pids.rb, line 43 def read sync do contents = IO.read(file_path) return if contents.empty? @pids = JSON.parse(contents) end end
save()
click to toggle source
# File lib/parallel_tests/pids.rb, line 51 def save sync { IO.write(file_path, pids.to_json) } end
sync() { || ... }
click to toggle source
# File lib/parallel_tests/pids.rb, line 55 def sync mutex.synchronize { yield } end