Class: ConsulWatcher::Storage::Disk

Inherits:
Object
  • Object
show all
Includes:
FlazmRubyHelpers::Class
Defined in:
lib/consul_watcher/storage/disk.rb

Overview

Disk storage for previous watch data

Instance Method Summary collapse

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

#fetchObject



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_filtersObject



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