Class: Starter::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/starter/config.rb

Class Method Summary collapse

Class Method Details

.config_fileObject



22
23
24
# File 'lib/starter/config.rb', line 22

def config_file
  File.join(@dest, '.config')
end

.read(dest: Dir.getwd) ⇒ Object



8
9
10
11
12
# File 'lib/starter/config.rb', line 8

def read(dest: Dir.getwd)
  @dest = dest
  return {} unless File.exist?(config_file)
  YAML.load_file(config_file)
end

.save(dest: Dir.getwd, content: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/starter/config.rb', line 14

def save(dest: Dir.getwd, content: nil)
  @dest = dest
  return if content.nil? || content.empty? || !content.is_a?(Hash)
  existent = File.exist?(config_file) ? YAML.load_file(config_file) : {}
  content = existent.merge(content)
  File.open(config_file, 'w') { |f| f.write(YAML.dump(content)) }
end