lib/uffizzi/config_file.rb in uffizzi-cli-0.7.3 vs lib/uffizzi/config_file.rb in uffizzi-cli-0.8.0

- old
+ new

@@ -6,21 +6,25 @@ module Uffizzi class ConfigFile CONFIG_PATH = "#{Dir.home}/.config/uffizzi/config_default.json" class << self + def config_path + CONFIG_PATH + end + def create(account_id, cookie, server) data = prepare_config_data(account_id, cookie, server) data.each_pair { |key, value| write_option(key, value) } end def delete - File.delete(CONFIG_PATH) if exists? + File.delete(config_path) if exists? end def exists? - File.exist?(CONFIG_PATH) + File.exist?(config_path) end def read_option(option) data = read return nil unless data.is_a?(Hash) @@ -77,11 +81,11 @@ data.key?(option) end def read - data = File.read(CONFIG_PATH) + data = File.read(config_path) options = data.split("\n") options.reduce({}) do |acc, option| key, value = option.split('=', 2) acc.merge({ key.strip.to_sym => value.strip }) end @@ -110,14 +114,14 @@ cookie: cookie, } end def create_file - dir = File.dirname(CONFIG_PATH) + dir = File.dirname(config_path) FileUtils.mkdir_p(dir) unless File.directory?(dir) - File.new(CONFIG_PATH, 'w') + File.new(config_path, 'w') end end end end