Class: RuboCop::Server::Cache
- Inherits:
-
Object
- Object
- RuboCop::Server::Cache
- Defined in:
- lib/rubocop/service/patch/server/cache.rb
Class Method Summary collapse
- .acquire_lock {|flock_result != false| ... } ⇒ Object
- .pid_running? ⇒ Boolean
- .project_dir_cache_key ⇒ Object
- .write_pid_file ⇒ Object
Class Method Details
.acquire_lock {|flock_result != false| ... } ⇒ Object
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
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_key ⇒ Object
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_file ⇒ Object
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 |