Class: HackathonDrone::Configuration
- Inherits:
-
Object
- Object
- HackathonDrone::Configuration
- Defined in:
- lib/hackathon_drone/configuration.rb
Constant Summary collapse
- CONFIG_FILE =
File.('~/.hackathon_drone')
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(project) ⇒ Configuration
constructor
—– Configuration file management —–.
- #reset ⇒ Object
- #save ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(project) ⇒ Configuration
—– Configuration file management —–
12 13 14 15 16 |
# File 'lib/hackathon_drone/configuration.rb', line 12 def initialize(project) @project = project @config = File.exists?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : {} @config[@project] ||= {} end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/hackathon_drone/configuration.rb', line 9 def project @project end |
Instance Method Details
#get(key) ⇒ Object
27 28 29 |
# File 'lib/hackathon_drone/configuration.rb', line 27 def get(key) @config[@project][key] end |
#reset ⇒ Object
18 19 20 21 |
# File 'lib/hackathon_drone/configuration.rb', line 18 def reset @config.delete(@project) save end |
#save ⇒ Object
23 24 25 |
# File 'lib/hackathon_drone/configuration.rb', line 23 def save File.open(CONFIG_FILE, 'w+') {|f| f.write(@config.to_yaml) } end |
#set(key, value) ⇒ Object
31 32 33 34 35 |
# File 'lib/hackathon_drone/configuration.rb', line 31 def set(key, value) @config[@project][key] = value save value end |