module FootballCli::Configuration

Constants

CONFIG_CONTENTS
CONFIG_FILE

Public Class Methods

api_token() click to toggle source
# File lib/football_cli/configuration.rb, line 35
def self.api_token
  config_data[:api_token] if config_data
end
config_data() click to toggle source
# File lib/football_cli/configuration.rb, line 43
def self.config_data
  YAML::load_file(config_file) if File.exist? config_file
end
config_file() click to toggle source
# File lib/football_cli/configuration.rb, line 39
def self.config_file
  File.join(ENV['HOME'], CONFIG_FILE)
end
create_config_file() click to toggle source
# File lib/football_cli/configuration.rb, line 31
def self.create_config_file
  File.open(config_file, 'w+') { |f| f.write(CONFIG_CONTENTS.to_yaml) }
end
update_value(value, key) click to toggle source
# File lib/football_cli/configuration.rb, line 22
def self.update_value(value, key)
  content = config_data
  content.send(:[]=, key, value)

  File.open(config_file, 'w') do |f|
    f.write(content.to_yaml)
  end
end
write(value, key, options) click to toggle source
# File lib/football_cli/configuration.rb, line 10
def self.write(value, key, options)
  create_config_file unless File.exist? config_file
  update_value(value, key) && return if options['update'] && !send(key).empty?

  if send(key).empty?
    puts "Updating config file with #{key}: #{value}"
    update_value(value, key)
  else
    puts "Do you want to overwrite #{key} provide --update option"
  end
end