Sha256: 6913279146bae87f3b435dc98528770a7c4377bec9ffe57d6699b1482d5f9acb

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

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_endpoint
      ENV.fetch("PHRASE_API_ENDPOINT", "https://phraseapp.com/api/v1")
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phrase-0.0.1 lib/phrase/tool_config.rb