Class: JSONVAT::FileCacheBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/json_vat/file_cache_backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "/tmp/jsonvat.json") ⇒ FileCacheBackend

Returns a new instance of FileCacheBackend.



6
7
8
# File 'lib/json_vat/file_cache_backend.rb', line 6

def initialize(path = "/tmp/jsonvat.json")
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/json_vat/file_cache_backend.rb', line 4

def path
  @path
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
# 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

#readObject



10
11
12
13
14
# File 'lib/json_vat/file_cache_backend.rb', line 10

def read
  File.read(self.path)
rescue Errno::ENOENT
  nil
end

#write(data) ⇒ Object



16
17
18
# File 'lib/json_vat/file_cache_backend.rb', line 16

def write(data)
  File.open(self.path, 'w') { |f| f.write(data) }
end