Class: ConsulWatcher::Storage::Disk
- Inherits:
-
Object
- Object
- ConsulWatcher::Storage::Disk
- Includes:
- FlazmRubyHelpers::Class
- Defined in:
- lib/consul_watcher/storage/disk.rb
Overview
Disk storage for previous watch data
Instance Method Summary collapse
- #fetch ⇒ Object
- #get_filters ⇒ Object
-
#initialize(storage_config) ⇒ Disk
constructor
A new instance of Disk.
- #push(data) ⇒ Object
Constructor Details
#initialize(storage_config) ⇒ Disk
Returns a new instance of Disk.
13 14 15 16 |
# File 'lib/consul_watcher/storage/disk.rb', line 13 def initialize(storage_config) initialize_variables(storage_config) FileUtils.mkdir_p(@cache_dir) unless File.directory?(@cache_dir) end |
Instance Method Details
#fetch ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/consul_watcher/storage/disk.rb', line 18 def fetch file = File.open(cache_file_name, mode: 'r') data = file.read file.close data = Zlib::Inflate.inflate(data) if @compress data rescue Errno::ENOENT '{}' end |
#get_filters ⇒ Object
34 35 36 |
# File 'lib/consul_watcher/storage/disk.rb', line 34 def get_filters nil end |
#push(data) ⇒ Object
28 29 30 31 32 |
# File 'lib/consul_watcher/storage/disk.rb', line 28 def push(data) file = File.open(cache_file_name, mode: 'w') file.write(@compress ? Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION) : data) file.close end |