class JSONVAT::FileCacheBackend

Attributes

path[RW]

Public Class Methods

new(path = "/tmp/jsonvat.json") click to toggle source
# File lib/json_vat/file_cache_backend.rb, line 6
def initialize(path = "/tmp/jsonvat.json")
  @path = path
end

Public Instance Methods

invalid?() click to toggle source
# File lib/json_vat/file_cache_backend.rb, line 20
def invalid?
  modified_time = current_modified_time

  if modified_time != @last_modified_time
    @last_modified_time = modified_time
    true
  else
    false
  end
end
read() click to toggle source
# File lib/json_vat/file_cache_backend.rb, line 10
def read
  File.read(self.path)
rescue Errno::ENOENT
  nil
end
write(data) click to toggle source
# File lib/json_vat/file_cache_backend.rb, line 16
def write(data)
  File.open(self.path, 'w') { |f| f.write(data) }
end

Private Instance Methods

current_modified_time() click to toggle source
# File lib/json_vat/file_cache_backend.rb, line 33
def current_modified_time
  File.stat(path).mtime.to_i
rescue Errno::ENOENT
  0
end