lib/negroku/config.rb in negroku-0.0.1 vs lib/negroku/config.rb in negroku-0.0.2

- old
+ new

@@ -1,36 +1,36 @@ require 'yaml' -# the yaml file where we'll write the settings -CONFIG_FILE = File.join(ENV['HOME'], ".negroku", "config.yaml") - def saveConfig(action, type, data) - # create the ~/.negroku folder - unless File.directory?(File.join(ENV['HOME'], ".negroku")) - puts "[Negroku] => Creating config file in #{ENV['HOME']}/.negroku" - %x(mkdir #{File.join(ENV['HOME'], ".negroku")}) - end - - # create an empty config.yaml file - unless File.exist?(CONFIG_FILE) - %x(touch #{CONFIG_FILE}) - end - # Load the yaml file - config = YAML.load_file(CONFIG_FILE) || {} + config_file = File.join(ENV['HOME'], ".negroku") + config = getConfig # If I need to add some multiple values - if action == "add" + if action === :add newData = config[type] || [] newData.push(data) newData.uniq! config = config.merge({ type => newData }) - elsif action == "remove" + elsif action === :remove #.. - elsif action == "replace" + elsif action === :replace #.. end - File.open(CONFIG_FILE, 'w') do |f| + File.open(config_file, 'w') do |f| f.write config.to_yaml end +end + +def getConfig + # load config from file + config_file = File.join(ENV['HOME'], ".negroku") + + # create an empty .negroku file + unless File.exist?(config_file) + %x(touch #{config_file}) + end + + # base config + YAML.load_file(config_file) || {} end \ No newline at end of file