Class: I18nliner::Commands::Check
- Inherits:
-
GenericCommand
- Object
- GenericCommand
- I18nliner::Commands::Check
- Defined in:
- lib/i18nliner/commands/check.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
- #check_file(file) ⇒ Object
- #check_files ⇒ Object
-
#initialize(options) ⇒ Check
constructor
A new instance of Check.
- #print_summary ⇒ Object
- #processors ⇒ Object
- #run ⇒ Object
- #success? ⇒ Boolean
Methods inherited from GenericCommand
Methods included from BasicFormatter
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() super @errors = [] @translations = I18nliner::Extractors::TranslationHash.new(I18nliner.manual_translations) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/i18nliner/commands/check.rb', line 11 def errors @errors end |
#translations ⇒ Object (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_files ⇒ Object
28 29 30 |
# File 'lib/i18nliner/commands/check.rb', line 28 def check_files processors.each &:check_files end |
#print_summary ⇒ Object
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 |
#processors ⇒ Object
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 |
#run ⇒ Object
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
41 42 43 |
# File 'lib/i18nliner/commands/check.rb', line 41 def success? @errors.empty? end |