Sha256: 1b8ccdb78c77f185623c4c5cfc008a97072644db67a75c53c485675a6b8d23d8

Contents?: true

Size: 1.53 KB

Versions: 21

Compression:

Stored size: 1.53 KB

Contents

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

require 'json'

class Phrase::Tool::Config
  def load
    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
    self
  end
  
  def secret
    config["secret"]
  end

  def secret=(new_secret)
    config["secret"] = new_secret
    save_config!
  end

  def default_locale
    config["default_locale"]
  end

  def default_locale=(new_default_locale)
    config["default_locale"] = new_default_locale
    save_config!
  end

  def domain
    config["domain"] || 'phrase'
  end

  def domain=(new_domain)
    config["domain"] = new_domain
    save_config!
  end

  def format
    config["format"]
  end

  def format=(new_domain)
    config["format"] = new_domain
    save_config!
  end
  
  def target_directory
    config["target_directory"]
  end

  def target_directory=(new_domain)
    config["target_directory"] = new_domain
    save_config!
  end

  def locale_directory
    config["locale_directory"]
  end

  def locale_directory=(new_domain)
    config["locale_directory"] = new_domain
    save_config!
  end

  def locale_filename
    config["locale_filename"]
  end

  def locale_filename=(new_domain)
    config["locale_filename"] = new_domain
    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

21 entries across 21 versions & 1 rubygems

Version Path
phrase-0.4.14 lib/phrase/tool/config.rb
phrase-0.4.13 lib/phrase/tool/config.rb
phrase-0.4.12 lib/phrase/tool/config.rb
phrase-0.4.11 lib/phrase/tool/config.rb
phrase-0.4.10 lib/phrase/tool/config.rb
phrase-0.4.9 lib/phrase/tool/config.rb
phrase-0.4.8 lib/phrase/tool/config.rb
phrase-0.4.7 lib/phrase/tool/config.rb
phrase-0.4.6 lib/phrase/tool/config.rb
phrase-0.4.5 lib/phrase/tool/config.rb
phrase-0.4.4 lib/phrase/tool/config.rb
phrase-0.4.3 lib/phrase/tool/config.rb
phrase-0.4.2 lib/phrase/tool/config.rb
phrase-0.4.1 lib/phrase/tool/config.rb
phrase-0.4.0 lib/phrase/tool/config.rb
phrase-0.3.7 lib/phrase/tool/config.rb
phrase-0.3.6 lib/phrase/tool/config.rb
phrase-0.3.5 lib/phrase/tool/config.rb
phrase-0.3.4 lib/phrase/tool/config.rb
phrase-0.3.3 lib/phrase/tool/config.rb