module Kosmos

Constants

VERSION

Public Class Methods

cache_dir() click to toggle source
# File lib/kosmos.rb, line 33
def cache_dir
  read_config[:cache_dir]
end
config() click to toggle source
# File lib/kosmos.rb, line 17
def config
  @config ||= Configuration.new
end
configure() { |config| ... } click to toggle source
# File lib/kosmos.rb, line 21
def configure
  yield(config)
end
load_ksp_path() click to toggle source
# File lib/kosmos.rb, line 29
def load_ksp_path
  read_config[:ksp_path]
end
save_ksp_path(path) click to toggle source
# File lib/kosmos.rb, line 25
def save_ksp_path(path)
  write_config(ksp_path: path)
end

Private Class Methods

config_path() click to toggle source
# File lib/kosmos.rb, line 59
def config_path
  File.join(Dir.home, ".kosmos")
end
read_config() click to toggle source
# File lib/kosmos.rb, line 48
def read_config
  FileUtils.touch(config_path)

  config = File.read(config_path)
  if config.empty?
    {}
  else
    JSON.parse(config, symbolize_names: true)
  end
end
write_config(opts) click to toggle source
# File lib/kosmos.rb, line 39
def write_config(opts)
  FileUtils.touch(config_path)

  config_to_write = JSON.pretty_generate(read_config.merge(opts))
  File.open(config_path, "w") do |file|
    file.write config_to_write
  end
end