Sha256: cdf935eb3ae68d85d0b89e499f4c1a9e7a098ee6c137d29630679a19261cef52

Contents?: true

Size: 899 Bytes

Versions: 1

Compression:

Stored size: 899 Bytes

Contents

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) || {}

  # If I need to add some multiple values
  if action == "add"
    newData = config[type] || []
    newData.push(data)
    newData.uniq!
    config = config.merge({ type => newData })
  elsif action == "remove"
    #..
  elsif action == "replace"
    #..
  end

  File.open(CONFIG_FILE, 'w') do |f|
    f.write config.to_yaml
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
negroku-0.0.1 lib/negroku/config.rb