class File
Public Class Methods
append(path, text)
click to toggle source
# File lib/core_extensions.rb, line 106 def self.append(path, text) open(path, 'a') { |f| f.write text } end
append_line(path, text)
click to toggle source
# File lib/core_extensions.rb, line 110 def self.append_line(path, text) open(path, 'a') do |f| f.write(text) f.puts end end
exclusive_append(path) { |read| ... }
click to toggle source
# File lib/core_extensions.rb, line 153 def self.exclusive_append(path) open(path, 'a+') do |f| f.flock(File::LOCK_EX) f.rewind string = yield f.read f.write(string) f.flush f.truncate(f.pos) end end
exclusive_modify(path) { |read| ... }
click to toggle source
# File lib/core_extensions.rb, line 141 def self.exclusive_modify(path) open(path, 'a+') do |f| f.flock(File::LOCK_EX) f.rewind string = yield f.read f.rewind f.write(string) f.flush f.truncate(f.pos) end end
exclusive_read(path)
click to toggle source
# File lib/core_extensions.rb, line 124 def self.exclusive_read(path) open(path, 'r') do |f| f.flock(File::LOCK_EX) f.read end end
exclusive_write(path, string)
click to toggle source
# File lib/core_extensions.rb, line 131 def self.exclusive_write(path, string) open(path, 'a+') do |f| f.flock(File::LOCK_EX) f.rewind f.write(string) f.flush f.truncate(f.pos) end end