Sha256: 931b46a780d6f050dc7b010436af50fbfe9c4d2f7838c1462d1cb4191b114358

Contents?: true

Size: 985 Bytes

Versions: 1

Compression:

Stored size: 985 Bytes

Contents

# -*- 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

Version data entries

1 entries across 1 versions & 1 rubygems

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