Class: Ardtweeno::ConfigReader
- Inherits:
-
Object
- Object
- Ardtweeno::ConfigReader
- Defined in:
- lib/ardtweeno/configreader.rb
Class Attribute Summary collapse
-
.data ⇒ Object
Returns the value of attribute data.
-
.log ⇒ Object
Returns the value of attribute log.
Class Method Summary collapse
-
.load(path, options = {}) ⇒ Object
Loads the database from disk.
-
.save(newData, path, options = {}) ⇒ Object
Saves the database to disk.
Class Attribute Details
.data ⇒ Object
Returns the value of attribute data.
33 34 35 |
# File 'lib/ardtweeno/configreader.rb', line 33 def data @data end |
.log ⇒ Object
Returns the value of attribute log.
33 34 35 |
# File 'lib/ardtweeno/configreader.rb', line 33 def log @log end |
Class Method Details
.load(path, options = {}) ⇒ Object
Loads the database from disk
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ardtweeno/configreader.rb', line 36 def load(path, ={}) @log = Ardtweeno.[:log] ||= Logger.new(STDOUT) @log.level = Ardtweeno.[:level] ||= Logger::DEBUG begin @data = YAML.load(File.open(path)) log.debug @data.inspect rescue ArgumentError => e log.fatal "Could not parse YAML: #{e.}" log.fatal e.backtrace exit() end return @data end |
.save(newData, path, options = {}) ⇒ Object
Saves the database to disk
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ardtweeno/configreader.rb', line 55 def save(newData, path, ={}) @log = [:log] ||= Logger.new(STDOUT) @log.level = [:level] ||= Logger::DEBUG @data = newData begin unless [:mode] == 'append' f = File.open(path, "w") else f = File.open(path, "a") end f.write(@data.to_yaml) f.close rescue Exception => e @log.fatal e. @log.fatal e.backtrace exit() end end |