Class: Nibble::Config
- Inherits:
-
Object
- Object
- Nibble::Config
- Defined in:
- lib/nibble/config.rb
Class Method Summary collapse
- .[](key) ⇒ Object
- .deep_merge(target, hash) ⇒ Object
- .defaults ⇒ Object
- .dump(path = "config.yml") ⇒ Object
- .load(path) ⇒ Object
Class Method Details
.[](key) ⇒ Object
27 28 29 |
# File 'lib/nibble/config.rb', line 27 def self.[](key) @config[key] end |
.deep_merge(target, hash) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nibble/config.rb', line 31 def self.deep_merge(target, hash) hash.keys.each do |key| if hash[key].is_a? Hash and target[key].is_a? Hash target[key] = deep_merge(target[key], hash[key]) next end target[key] = hash[key] end target end |
.defaults ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/nibble/config.rb', line 17 def self.defaults { connection: {ip: "10.0.1.200"}, wakeup: {silent: 0}, ttl: {voice: "andreas", nocache: 0, mute: 0}, leds: {color: "00FF00", color2: "00FF00", pulse: 0, speed: 700, no_memory: 0}, ears: {noreset: 1, left: 0, right: 0}, } end |
.dump(path = "config.yml") ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/nibble/config.rb', line 5 def self.dump(path = "config.yml") File.open(path, 'w') do |f| puts "writing defaults to #{File.absolute_path(f)}" f.write(YAML.dump(defaults)) end end |
.load(path) ⇒ Object
13 14 15 |
# File 'lib/nibble/config.rb', line 13 def self.load(path) @config = deep_merge(defaults, YAML.load(File.read(path))) end |