Class: Monkey::Config
- Inherits:
-
Object
- Object
- Monkey::Config
- Defined in:
- lib/monkey/config.rb
Constant Summary collapse
- CONFIG_PATH =
File.join(current_dir, '../../config.yml')
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #[](option) ⇒ Object
- #[]=(option, val) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #save! ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/monkey/config.rb', line 9 def initialize FileUtils.touch(CONFIG_PATH) config_file = File.open(CONFIG_PATH, "rt") hash = YAML.load(config_file) if hash @hash = hash else @hash = {} end config_file.close end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
21 22 23 |
# File 'lib/monkey/config.rb', line 21 def hash @hash end |
Instance Method Details
#[](option) ⇒ Object
27 28 29 |
# File 'lib/monkey/config.rb', line 27 def [](option) @hash[option] end |
#[]=(option, val) ⇒ Object
31 32 33 |
# File 'lib/monkey/config.rb', line 31 def []=(option, val) @hash[option] = val end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/monkey/config.rb', line 23 def empty? @hash.empty? end |
#save! ⇒ Object
35 36 37 |
# File 'lib/monkey/config.rb', line 35 def save! File.open(CONFIG_PATH, "w") {|f| f.write(@hash.to_yaml) } end |