module Tacape::Tools::Helpers::JsonConfig::InstanceMethods
Public Instance Methods
load_config()
click to toggle source
# File lib/tacape/tools/helpers/json_config.rb, line 43 def load_config if File.exist? @config_file @config = JSON.parse(File.read(@config_file)) unless @config.class==Hash raise 'Corrupt JSON file!' end return else setup end end
save_config()
click to toggle source
# File lib/tacape/tools/helpers/json_config.rb, line 55 def save_config unless File.exist? File.dirname(@config_file) FileUtils.mkdir_p(File.dirname(@config_file)) end File.open(@config_file, 'w') {|f| f.write(@config.to_json) } end
setup()
click to toggle source
# File lib/tacape/tools/helpers/json_config.rb, line 6 def setup @config={} @config_template.each do |k,v| tip=' use comma, no spaces' if v.class==Array if @config_template[k]!=nil && @config_template[k]!='' question = "#{k} [default=#{@config_template[k]}]#{tip}:" else question = "#{k}#{tip}:" end input = ask(question) unless input.empty? case v when String @config[k]=input when Array @config[k]=input.split(',') else puts "Bailed on #{v.class}" end if k.include?('folder') || k.include?('file') if File.dirname(@config[k]) == '.' @config[k]="#{ENV['HOME']}/#{@config[k]}" end unless File.exist?(File.dirname(@config[k])) FileUtils.mkdir_p(File.dirname(@config[k])) end end else @config[k]=@config_template[k] end end save_config end