Class: Jiragit::Configuration
- Inherits:
-
Object
- Object
- Jiragit::Configuration
- Defined in:
- lib/jiragit/configuration.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #create ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(location) ⇒ Configuration
constructor
A new instance of Configuration.
- #load ⇒ Object
- #load_or_create ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(location) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 |
# File 'lib/jiragit/configuration.rb', line 7 def initialize(location) self.location = location load_or_create end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/jiragit/configuration.rb', line 31 def [](key) config[key] end |
#[]=(key, value) ⇒ Object
35 36 37 38 |
# File 'lib/jiragit/configuration.rb', line 35 def []=(key, value) config[key] = value save end |
#create ⇒ Object
21 22 23 24 25 |
# File 'lib/jiragit/configuration.rb', line 21 def create self.config = {} save config end |
#include?(key) ⇒ Boolean
40 41 42 |
# File 'lib/jiragit/configuration.rb', line 40 def include?(key) config.include?(key) end |
#load ⇒ Object
16 17 18 19 |
# File 'lib/jiragit/configuration.rb', line 16 def load return false unless File.exists?(location) self.config = YAML.load(File.read(location)) end |
#load_or_create ⇒ Object
12 13 14 |
# File 'lib/jiragit/configuration.rb', line 12 def load_or_create self.config = load || create end |
#save ⇒ Object
27 28 29 |
# File 'lib/jiragit/configuration.rb', line 27 def save File.open(location, 'w+') { |file| file.write YAML.dump(config) } end |