Class: TeamboxThingsSync::ConfigStore

Inherits:
Object
  • Object
show all
Defined in:
lib/teambox-things-sync/config_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ConfigStore

Returns a new instance of ConfigStore.



7
8
9
# File 'lib/teambox-things-sync/config_store.rb', line 7

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/teambox-things-sync/config_store.rb', line 5

def file
  @file
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
# File 'lib/teambox-things-sync/config_store.rb', line 16

def [](key)
  load
  @config[key]
end

#[]=(key, value) ⇒ Object



21
22
23
# File 'lib/teambox-things-sync/config_store.rb', line 21

def []=(key, value)
  @config[key] = value
end

#delete(*keys) ⇒ Object



25
26
27
28
29
# File 'lib/teambox-things-sync/config_store.rb', line 25

def delete(*keys)
  keys.each { |key| @config.delete(key) }
  save
  self
end

#loadObject



11
12
13
14
# File 'lib/teambox-things-sync/config_store.rb', line 11

def load
  @config ||= YAML::load(open(file))
  self
end

#saveObject



37
38
39
40
# File 'lib/teambox-things-sync/config_store.rb', line 37

def save
  File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
  self
end

#update(c = {}) ⇒ Object



31
32
33
34
35
# File 'lib/teambox-things-sync/config_store.rb', line 31

def update(c={})
  @config.merge!(c)
  save
  self
end