class ConfigManager

Public Instance Methods

get_all() click to toggle source
# File lib/cadbury/helpers/config_manager.rb, line 6
def get_all
  config = File.open Global::ENV_FILE_PATH
  config_json = JSON.load config
  config.close
  config_json
rescue StandardError => e
  if e.message.include? "No such file or directory"
    puts "Error: No Environment file found at #{ENV_FILE_PATH}."
    puts "Please run 'cadburybot env set <env-name>' command to create a new environment"
  else
    puts "Error: #{e.message}"
  end
  exit
end
get_by_env(env:) click to toggle source
# File lib/cadbury/helpers/config_manager.rb, line 21
def get_by_env(env:)
  get_all[env]
end
save(configs) click to toggle source
# File lib/cadbury/helpers/config_manager.rb, line 25
def save(configs)
  FileUtils.mkdir_p Global::APIBOT_DIR
  File.open(Global::ENV_FILE_PATH, "w") do |f|
    f.write(JSON.pretty_generate(configs))
    puts "Config updated successfully in #{Global::ENV_FILE_PATH}"
  end
end