Class: JSONVAT::FileCacheBackend
- Inherits:
-
Object
- Object
- JSONVAT::FileCacheBackend
- Defined in:
- lib/json_vat/file_cache_backend.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path = "/tmp/jsonvat.json") ⇒ FileCacheBackend
constructor
A new instance of FileCacheBackend.
- #invalid? ⇒ Boolean
- #read ⇒ Object
- #write(data) ⇒ Object
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
#path ⇒ Object
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
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 |
#read ⇒ Object
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 |