Class: CertOpenDataVisualizer::DummyCacher

Inherits:
Object
  • Object
show all
Defined in:
lib/cert_open_data_visualizer/dummy_cacher.rb

Instance Method Summary collapse

Constructor Details

#initializeDummyCacher

Returns a new instance of DummyCacher.



7
8
9
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 7

def initialize
  FileUtils.mkdir_p(path)
end

Instance Method Details

#cache_file(file) ⇒ Object

Yep, well just overwrite it if it exists



12
13
14
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 12

def cache_file(file)
  FileUtils.cp(file, path)
end

#clean!Object



53
54
55
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 53

def clean!
  FileUtils.rm_rf path
end

#file_exists?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 26

def file_exists?(file_name)
  File.exists? get_from_cache(file_name)
end

#find_files_matching(matcher) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 41

def find_files_matching(matcher)
  files = []
  Dir.chdir(path) do
    files = Dir.glob(matcher)
  end
  files
end

#get_from_cache(file_name) ⇒ Object



22
23
24
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 22

def get_from_cache(file_name)
  File.join(path,  file_name)
end

#pathObject



49
50
51
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 49

def path
  File.join(Dir.tmpdir, "cert")
end

#tmpdir_pathObject



30
31
32
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 30

def tmpdir_path
  Dir.tmpdir
end

#unzip_file(file_name) ⇒ Object



34
35
36
37
38
39
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 34

def unzip_file(file_name)
  Dir.chdir(path) do
    # Because I have found rubyzip to be buggy, we rely that your system has zip-command available
    `unzip -o  #{file_name}`
  end
end

#write_file_to_cache(filename, contents) ⇒ Object



16
17
18
19
20
# File 'lib/cert_open_data_visualizer/dummy_cacher.rb', line 16

def write_file_to_cache(filename, contents)
  Dir.chdir(path) do
    File.open(filename, "wb") { |file| file.write(contents) }
  end
end