Class: Confman::DataStore

Inherits:
Object
  • Object
show all
Defined in:
lib/confman/data_store.rb

Constant Summary collapse

@@dir =
'.confman'

Class Method Summary collapse

Class Method Details

.compute_file_path(key, conf_set_name) ⇒ Object



31
32
33
# File 'lib/confman/data_store.rb', line 31

def self.compute_file_path(key, conf_set_name)
  "#{dir}/#{key}_#{Digest::MD5.hexdigest conf_set_name}"
end

.create_directory_if_not_presentObject



27
28
29
# File 'lib/confman/data_store.rb', line 27

def self.create_directory_if_not_present
  Dir.mkdir(@@dir) unless Dir.exists?(dir)
end

.dirObject



9
10
11
# File 'lib/confman/data_store.rb', line 9

def self.dir
  @@dir
end

.dir=(dir) ⇒ Object



5
6
7
# File 'lib/confman/data_store.rb', line 5

def self.dir= dir
  @@dir = dir
end

.read(key, conf_set_name) ⇒ Object



22
23
24
25
# File 'lib/confman/data_store.rb', line 22

def self.read(key, conf_set_name)
  filepath = compute_file_path(key, conf_set_name)
  IO.read(filepath) if File.exists?(filepath)
end

.write(key, conf_set_name, data) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/confman/data_store.rb', line 13

def self.write(key, conf_set_name, data)
  create_directory_if_not_present

  filepath = compute_file_path(key, conf_set_name)
  File.open filepath, "w" do |file|
    file.write(data)
  end
end