Class: Cp8Cli::ConfigStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cp8_cli/config_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ConfigStore

Returns a new instance of ConfigStore.



5
6
7
# File 'lib/cp8_cli/config_store.rb', line 5

def initialize(path)
  @path = path
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/cp8_cli/config_store.rb', line 9

def [](key)
  data[key]
end

#exist?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cp8_cli/config_store.rb', line 13

def exist?
  File.exist?(path)
end

#move_to(new_path) ⇒ Object



17
18
19
20
# File 'lib/cp8_cli/config_store.rb', line 17

def move_to(new_path)
  File.rename(path, new_path)
  @path = new_path
end

#save(key, value) ⇒ Object



22
23
24
25
26
27
# File 'lib/cp8_cli/config_store.rb', line 22

def save(key, value)
  data[key] = value
  File.new(path, "w") unless exist?
  File.open(path, "w") { |f| f.write(data.to_yaml) }
  value
end