Module: Config
Constant Summary collapse
- GLOBAL_FILENAME =
"#{ENV['HOME']}/.enzyme.yml"
- PROJECT_FILENAME =
"./.enzyme.yml"
Instance Method Summary collapse
Instance Method Details
#get(key) ⇒ Object
28 29 30 31 32 |
# File 'lib/commands/config.rb', line 28 def get(key) s = $settings key.split('.').each { |o| s = s[o] } if key s end |
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |