class I18nLinter::Runner

Public Class Methods

new(options, config) click to toggle source
# File lib/i18n_linter/runner.rb, line 9
def initialize(options, config)
  @options = options
  @linter = I18nLinter.linter.new(options, config)
end

Public Instance Methods

run() click to toggle source
# File lib/i18n_linter/runner.rb, line 14
def run
  $stdout = StringIO.new

  result = @options.files.map { |file|
    lint_result = lint(file)
    if lint_result.success?
      true
    else
      @linter.show_errors(lint_result)
      false
    end
  }.all?

  handle_results

  $stdout = STDOUT

  result
end

Private Instance Methods

handle_results() click to toggle source
# File lib/i18n_linter/runner.rb, line 36
def handle_results
  output_file = @options.out_file
  output = $stdout.string

  if output_file
    File.open(output_file, 'w') do |file|
      file.write output
    end
  else
    STDOUT.puts output
  end
end
lint(filename) click to toggle source
# File lib/i18n_linter/runner.rb, line 49
def lint(filename)
  file = File.read(filename)
  @linter.lint(filename: filename, file: file)
end