Sha256: fae88d95c3bcc12ffd7268c886f465ca3b8020150e46d38c7e082680bf2968e1

Contents?: true

Size: 648 Bytes

Versions: 8

Compression:

Stored size: 648 Bytes

Contents

# -*- encoding : utf-8 -*-

require 'phrase'
require 'json'

class Phrase::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
  
private  
  def config
    @config ||= {}
  end

  def save_config!
    File.open(".phrase", "w+") do |file|
      file.write(JSON.pretty_generate(config))
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
phrase-0.2.0 lib/phrase/tool_config.rb
phrase-0.2.0.beta.8 lib/phrase/tool_config.rb
phrase-0.2.0.beta.7 lib/phrase/tool_config.rb
phrase-0.2.0.beta.6 lib/phrase/tool_config.rb
phrase-0.2.0.beta.5 lib/phrase/tool_config.rb
phrase-0.2.0.beta.4 lib/phrase/tool_config.rb
phrase-0.2.0.beta.3 lib/phrase/tool_config.rb
phrase-0.2.0.beta.2 lib/phrase/tool_config.rb