Class: Jarbs::Config
- Inherits:
-
Object
- Object
- Jarbs::Config
- Defined in:
- lib/jarbs/config.rb
Constant Summary collapse
- FILE_NAME =
'.jarbs'
Class Method Summary collapse
Instance Method Summary collapse
- #get(key, &block) ⇒ Object
-
#initialize(file = FILE_NAME) ⇒ Config
constructor
A new instance of Config.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(file = FILE_NAME) ⇒ Config
Returns a new instance of Config.
9 10 11 12 |
# File 'lib/jarbs/config.rb', line 9 def initialize(file=FILE_NAME) @file = file @config = read end |
Class Method Details
.touch ⇒ Object
5 6 7 |
# File 'lib/jarbs/config.rb', line 5 def self.touch File.open(FILE_NAME, 'w') {|f| f.write JSON.pretty_generate({}) } end |
Instance Method Details
#get(key, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jarbs/config.rb', line 19 def get(key, &block) val = @config[key] if !val && block_given? val = yield set(key, val) end val end |
#set(key, value) ⇒ Object
14 15 16 17 |
# File 'lib/jarbs/config.rb', line 14 def set(key, value) @config[key] = value finalize end |