Class: Jiragit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jiragit/configuration.rb

Instance Method Summary collapse

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

#createObject



21
22
23
24
25
# File 'lib/jiragit/configuration.rb', line 21

def create
  self.config = {}
  save
  config
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jiragit/configuration.rb', line 40

def include?(key)
  config.include?(key)
end

#loadObject



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_createObject



12
13
14
# File 'lib/jiragit/configuration.rb', line 12

def load_or_create
  self.config = load || create
end

#saveObject



27
28
29
# File 'lib/jiragit/configuration.rb', line 27

def save
  File.open(location, 'w+') { |file| file.write YAML.dump(config) }
end