class Cp8Cli::ConfigStore

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/cp8_cli/config_store.rb, line 5
def initialize(path)
  @path = path
end

Public Instance Methods

[](key) click to toggle source
# File lib/cp8_cli/config_store.rb, line 9
def [](key)
  data[key]
end
exist?() click to toggle source
# File lib/cp8_cli/config_store.rb, line 13
def exist?
  File.exist?(path)
end
move_to(new_path) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

data() click to toggle source
# File lib/cp8_cli/config_store.rb, line 33
def data
  @_data ||= load_data
end
load_data() click to toggle source
# File lib/cp8_cli/config_store.rb, line 37
def load_data
  YAML.load File.read(path)
rescue
  {}
end