Class: ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cadbury/helpers/config_manager.rb

Instance Method Summary collapse

Instance Method Details

#get_allObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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:) ⇒ Object



21
22
23
# File 'lib/cadbury/helpers/config_manager.rb', line 21

def get_by_env(env:)
  get_all[env]
end

#save(configs) ⇒ Object



25
26
27
28
29
30
31
# 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