Class: RuboCop::Server::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/service/patch/server/cache.rb

Class Method Summary collapse

Class Method Details

.acquire_lock {|flock_result != false| ... } ⇒ Object

Yields:

  • (flock_result != false)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubocop/service/patch/server/cache.rb', line 19

def acquire_lock
  lock_file = File.open(lock_path, File::CREAT)
  # flock returns 0 if successful, and false if not.
  flock_result = lock_file.flock(File::LOCK_EX | File::LOCK_NB)
  # rubocop:disable Style/GlobalVars
  $unlocker = -> do
    next if lock_file.closed?
    lock_file.flock(File::LOCK_UN)
    lock_file.close
  end
  # rubocop:enable Style/GlobalVars
  yield flock_result != false
end

.pid_running?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/rubocop/service/patch/server/cache.rb', line 33

def pid_running?
  Process.kill(0, pid_path.read.to_i) == 1
rescue Errno::ESRCH, Errno::ENOENT
  false
end

.project_dir_cache_keyObject



7
8
9
# File 'lib/rubocop/service/patch/server/cache.rb', line 7

def project_dir_cache_key
  @project_dir_cache_key ||= project_dir.tr("/:", "++")
end

.write_pid_fileObject



11
12
13
14
15
16
17
# File 'lib/rubocop/service/patch/server/cache.rb', line 11

def write_pid_file
  pid_path.write(Process.pid)
  yield
ensure
  $unlocker&.call # rubocop:disable Style/GlobalVars
  dir.rmtree
end