module Config
Constants
- GLOBAL_FILENAME
- PROJECT_FILENAME
Public Instance Methods
get(key)
click to toggle source
# File lib/commands/config.rb, line 28 def get(key) s = $settings key.split('.').each { |o| s = s[o] } if key s end
run()
click to toggle source
# File lib/commands/config.rb, line 10 def run() global = ARGV.delete('--global') ARGV.reject { |x| x.start_with?("-") } key = ARGV.shift value = ARGV.shift unless value === nil set(key, value, global) else val = get(key) if val.is_a?(Array) || val.is_a?(Hash) || val.is_a?(Settings) puts val.to_hash.to_yaml else puts val.to_s end end end
set(key, value, global=false)
click to toggle source
# File lib/commands/config.rb, line 34 def set(key, value, global=false) filename = global ? GLOBAL_FILENAME : PROJECT_FILENAME settings = YAML.load_file(filename) || {} # FIXME: This could be simplified... heaps. newSettings = {} n = newSettings keys = key.to_s.split(".") keys.each do |k| k = k.to_i if k == k.to_i.to_s n[k] = (k == keys.last) ? value : {} n = n[k] end settings = settings.deep_merge(newSettings) File.open(filename, "w") { |f| f.write(settings.to_yaml) } end