class Guac::Config
Constants
- CONFIG_FILE
- DEFAULTS_FILE
- OH_NO_YOU_DONTS
- REQUIRED_FIELDS
Public Class Methods
configs(reload: false)
click to toggle source
# File lib/guac/config.rb, line 42 def configs(reload: false) if reload parse(CONFIG_FILE) else @configs ||= parse(CONFIG_FILE) end end
defaults()
click to toggle source
# File lib/guac/config.rb, line 38 def defaults parse(DEFAULTS_FILE) end
load()
click to toggle source
# File lib/guac/config.rb, line 12 def load if configs.nil? error = "#{CONFIG_FILE} not found\n".yellow error += 'Please run ' + '`guac setup`'.green raise Guac::Commands::Error, error end missing_fields = REQUIRED_FIELDS.select { |f| configs[f].nil? || configs[f].empty? } if missing_fields.any? error = "Missing config for #{missing_fields.join(', ')} \n".yellow error += 'Please run ' + '`guac setup`'.green raise Guac::Commands::Error, error end strategy = configs[:pull_strategy] cmds = OH_NO_YOU_DONTS.select { |cmd| strategy.include?("git #{cmd}") } if cmds.any? error = "Your pull strategy is dangerous! `#{strategy.bold}`\n".red error += "You really shouldn't use #{cmds.join(', ').bold}\n".yellow error += 'Please run ' + '`guac setup`'.green raise Guac::Commands::Error, error end configs end
save_configs(body)
click to toggle source
# File lib/guac/config.rb, line 50 def save_configs(body) file = File.new(CONFIG_FILE, 'w') file.puts(body.to_yaml) file.close end
Private Class Methods
parse(file)
click to toggle source
# File lib/guac/config.rb, line 58 def parse(file) return nil unless File.exist?(file) res = YAML.load(File.read(file)) # Empty yaml returns `false` res || nil end