class Grass::FileSync::FileProxy

Public Class Methods

new(source) click to toggle source
# File lib/grass/file_sync.rb, line 9
def initialize source
  @source = source
  FileUtils.mkdir_p File.dirname(@source.filepath)
  exists? ? read : write(@source.raw)
end

Public Instance Methods

delete() click to toggle source
# File lib/grass/file_sync.rb, line 36
def delete
  File.delete(@source.filepath) rescue nil
end
dirty?() click to toggle source
# File lib/grass/file_sync.rb, line 40
def dirty?
  @source.raw.nil? || File.mtime(@source.filepath).to_i > @source.updated_at.to_i
end
exists?() click to toggle source
# File lib/grass/file_sync.rb, line 15
def exists?
  File.exists? @source.filepath
end
read() click to toggle source
# File lib/grass/file_sync.rb, line 19
def read
  begin
    value = File.read(@source.filepath)
    @source.update(raw: value) if dirty?
    value
  end rescue nil
end
write(value) click to toggle source
# File lib/grass/file_sync.rb, line 27
def write value
  begin
    File.open(@source.filepath,File::RDWR|File::CREAT){ |f| 
      f.truncate(0); f.rewind; f.write(value)
    }
    value
  end rescue nil
end