module Services::AppConfig

Public Class Methods

all() click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 24
def all
  config_file
end
delete(key) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 20
def delete(key)
  write_config_file(config_file.except(key))
end
get(key) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 10
def get(key)
  config_file.fetch(key, nil)
end
get_or_exit(key) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 6
def get_or_exit(key)
  get(key) || exit_due_key_not_present(key)
end
reset_all() click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 28
def reset_all
  write_config_file({})
end
set(key, value) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 14
def set(key, value)
  new_config_file = config_file
  new_config_file[key] = value
  write_config_file(new_config_file)
end

Private Class Methods

config_file() click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 38
def config_file
  File.new(CONFIG_FILE_PATH, 'a')
  YAML.load_file(CONFIG_FILE_PATH) || {}
end
exit_due_key_not_present(key) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 43
def exit_due_key_not_present(key)
  puts "#{key.upcase} not specified. "\
       'Please check command usage or specify it using the CONFIG command'
  exit 0
end
write_config_file(new_config_file) click to toggle source
# File lib/busbar_cli/services/app_config.rb, line 34
def write_config_file(new_config_file)
  File.open(CONFIG_FILE_PATH, 'w') { |f| f.write new_config_file.to_yaml }
end