Class: Qnotifier::Storage
- Inherits:
-
Object
- Object
- Qnotifier::Storage
- Defined in:
- lib/storage.rb
Constant Summary collapse
- @@stored_variables =
{}
- @@restored =
false
Class Method Summary collapse
- .delete(key) ⇒ Object
- .get(key) ⇒ Object
- .put(key, value) ⇒ Object
- .restore ⇒ Object
- .save ⇒ Object
- .wipe ⇒ Object
Class Method Details
.delete(key) ⇒ Object
45 46 47 48 |
# File 'lib/storage.rb', line 45 def self.delete(key) restore unless @@restored @@stored_variables.delete(key) end |
.get(key) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/storage.rb', line 22 def self.get(key) restore unless @@restored if @@stored_variables[key] return @@stored_variables[key] else return nil end end |
.put(key, value) ⇒ Object
31 32 33 34 |
# File 'lib/storage.rb', line 31 def self.put(key, value) restore unless @@restored @@stored_variables[key] = value end |
.restore ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/storage.rb', line 10 def self.restore saved_variables = "/var/lib/qnotifier/saved_variables.yml" begin var_dir = "/var/lib/qnotifier" FileUtils.mkdir_p var_dir unless File.exists?(var_dir) @@stored_variables = YAML::load(File.open(saved_variables)) rescue Exception => e # Qnotifier.log.debug "Error loading stored variables file. #{e.message}" end @@restored = true end |
.save ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/storage.rb', line 50 def self.save saved_variables = "/var/lib/qnotifier/saved_variables.yml" begin File.open(saved_variables, "w") do |f| f.write(YAML::dump(@@stored_variables)) end rescue Exception => e Qnotifier.log.error "Error saving stored variables file. #{e.}" end end |