# -*- encoding : utf-8 -*- require 'json' module PhraseGem class ToolConfig def initialize if File.exist?(".phrase") begin contents = File.read(".phrase") @config = JSON.parse(contents) rescue JSON::ParserError => err $stderr.puts "Could not parse config file: #{err}" end end end def secret config["secret"] end def secret=(new_secret) config["secret"] = new_secret save_config! end def api_port ENV.fetch("PHRASE_API_PORT", "443") end def api_host ENV.fetch("PHRASE_API_HOST", "phraseapp.com") end def api_path_prefix "/api/v1" end def api_use_ssl ENV.fetch("PHRASE_API_USE_SSL", "1") end private def config @config ||= {} end def save_config! File.open(".phrase", "w+") do |file| file.write(JSON.pretty_generate(config)) end end end end