Sha256: 9edc479a866d8b42446ed46cb9656a70cc7aa424feb15c1faee69eb58b1e340e

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'yaml'
require 'missing_translation/yaml_processor'

module MissingTranslation
  class Util

    def self.uncommitted_changes?
      status = `git status --porcelain`
      return false if $CHILD_STATUS.success? && status.empty?

      error = if $CHILD_STATUS.success?
                "You have uncommitted code. Please commit or stash your changes before continuing"
              else
                "You do not have Git installed. Please install Git, and commit your changes before continuing"
              end
      p error
      true
    end

    def self.commit_all_changes(message)
      status = `git add .`
      status = system "git commit -m \"#{message}\""
    end

    def self.sort_file(filepath)
      content = YAML.load_file(filepath)
      hash = MissingTranslation::YamlProcessor.denormalize_translations_hash(content)
      translations = MissingTranslation::YamlProcessor.normalize_translations_hash(hash)

      File.write(filepath, translations.to_yaml)
    end

    def self.sort(file_pattern = "./config/locales/#{file_extension}/*.yml")
      file_pathnames = Dir[file_pattern]
      return unless file_pathnames && file_pathnames.size > 0

      file_pathnames.each do |filepath|
        sort_file(filepath)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
missing_translation-0.4.2 lib/missing_translation/util.rb
missing_translation-0.4.1 lib/missing_translation/util.rb
missing_translation-0.4.0 lib/missing_translation/util.rb
missing_translation-0.3.0 lib/missing_translation/util.rb