Class: Scatter::Config
- Inherits:
-
Object
- Object
- Scatter::Config
- Defined in:
- lib/scatter/config.rb
Constant Summary collapse
- CONFIG_FILE =
"#{Dir.home}/.scatterconfig"
- DEFAULTS =
{'directory' => "#{Dir.home}/.deploys"}
Class Method Summary collapse
- .get(key = nil) ⇒ Object
- .parse ⇒ Object
- .save(options) ⇒ Object
- .set(key, value) ⇒ Object
- .show(key = nil) ⇒ Object
Class Method Details
.get(key = nil) ⇒ Object
18 19 20 21 |
# File 'lib/scatter/config.rb', line 18 def self.get(key=nil) config = self.parse key ? config[key] : config end |
.parse ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/scatter/config.rb', line 8 def self.parse return DEFAULTS unless File.exists? CONFIG_FILE begin return DEFAULTS.merge YAML.load(File.read CONFIG_FILE) rescue abort "There was a problem parsing #{CONFIG_FILE}, it should be valid YAML" end end |
.save(options) ⇒ Object
23 24 25 26 27 |
# File 'lib/scatter/config.rb', line 23 def self.save() File.open(CONFIG_FILE, 'w') do |f| f.write .to_yaml end end |
.set(key, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/scatter/config.rb', line 29 def self.set(key, value) config = get config[key] = value save config end |
.show(key = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/scatter/config.rb', line 35 def self.show(key=nil) if key value = get[key] else value = get end value.to_yaml end |