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 8
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 13
def add(pid)
  pids << pid.to_i
  save
end
all() click to toggle source
# File lib/parallel_tests/pids.rb, line 28
def all
  read
  pids
end
count() click to toggle source
# File lib/parallel_tests/pids.rb, line 23
def count
  read
  pids.count
end
delete(pid) click to toggle source
# File lib/parallel_tests/pids.rb, line 18
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 39
def clear
  @pids = []
  save
end
pids() click to toggle source
# File lib/parallel_tests/pids.rb, line 35
def pids
  @pids ||= []
end
read() click to toggle source
# File lib/parallel_tests/pids.rb, line 44
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 52
def save
  sync { IO.write(file_path, pids.to_json) }
end
sync(&block) click to toggle source
# File lib/parallel_tests/pids.rb, line 56
def sync(&block)
  mutex.synchronize(&block)
end