Class: I18nliner::Commands::Check

Inherits:
GenericCommand show all
Defined in:
lib/i18nliner/commands/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericCommand

run

Methods included from BasicFormatter

#green, #red

Constructor Details

#initialize(options) ⇒ Check

Returns a new instance of Check.


13
14
15
16
17
# File 'lib/i18nliner/commands/check.rb', line 13

def initialize(options)
  super
  @errors = []
  @translations = I18nliner::Extractors::TranslationHash.new(I18nliner.manual_translations)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors


11
12
13
# File 'lib/i18nliner/commands/check.rb', line 11

def errors
  @errors
end

#translationsObject (readonly)

Returns the value of attribute translations


11
12
13
# File 'lib/i18nliner/commands/check.rb', line 11

def translations
  @translations
end

Instance Method Details

#check_file(file) ⇒ Object


32
33
34
35
36
37
38
39
# File 'lib/i18nliner/commands/check.rb', line 32

def check_file(file)
  if yield file
    print green(".") unless @options[:silent]
  end
rescue SyntaxError, StandardError, ExtractionError
  @errors << "#{$!}\n#{file}"
  print red("F") unless @options[:silent]
end

#check_filesObject


28
29
30
# File 'lib/i18nliner/commands/check.rb', line 28

def check_files
  processors.each &:check_files
end

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/i18nliner/commands/check.rb', line 45

def print_summary
  translation_count = processors.sum(&:translation_count)
  file_count = processors.sum(&:file_count)

  print "\n\n"

  @errors.each_with_index do |error, i|
    puts "#{i+1})"
    puts red(error)
    print "\n"
  end

  print "Finished in #{Time.now - @start} seconds\n\n"
  summary = "#{file_count} files, #{translation_count} strings, #{@errors.size} failures"
  puts success? ? green(summary) : red(summary)
end

#processorsObject


19
20
21
22
23
24
25
26
# File 'lib/i18nliner/commands/check.rb', line 19

def processors
  @processors ||= I18nliner::Processors.all.map do |klass|
    klass.new @translations,
              :only => @options[:only],
              :translations => @translations,
              :checker => method(:check_file)
  end
end

#runObject


62
63
64
65
66
# File 'lib/i18nliner/commands/check.rb', line 62

def run
  check_files
  print_summary unless @options[:silent]
  success?
end

#success?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/i18nliner/commands/check.rb', line 41

def success?
  @errors.empty?
end