Class: RuboCop::Formatter::FormatterSet
- Inherits:
-
Array
- Object
- Array
- RuboCop::Formatter::FormatterSet
- Defined in:
- lib/rubocop/formatter/formatter_set.rb
Overview
This is a collection of formatters. A FormatterSet can hold multiple formatter instances and provides transparent formatter API methods which invoke same method of each formatters.
Constant Summary collapse
- BUILTIN_FORMATTERS_FOR_KEYS =
{ 'progress' => ProgressFormatter, 'simple' => SimpleTextFormatter, 'clang' => ClangStyleFormatter, 'fuubar' => FuubarStyleFormatter, 'emacs' => EmacsStyleFormatter, 'json' => JSONFormatter, 'html' => HTMLFormatter, 'files' => FileListFormatter, 'offenses' => OffenseCountFormatter, 'disabled' => DisabledLinesFormatter, 'worst' => WorstOffendersFormatter }.freeze
- FORMATTER_APIS =
[:started, :finished].freeze
Instance Method Summary collapse
- #add_formatter(formatter_type, output_path = nil) ⇒ Object
- #close_output_files ⇒ Object
- #file_finished(file, offenses) ⇒ Object
- #file_started(file, options) ⇒ Object
-
#initialize(options = {}) ⇒ FormatterSet
constructor
A new instance of FormatterSet.
Constructor Details
#initialize(options = {}) ⇒ FormatterSet
Returns a new instance of FormatterSet.
33 34 35 |
# File 'lib/rubocop/formatter/formatter_set.rb', line 33 def initialize( = {}) @options = # CLI options end |
Instance Method Details
#add_formatter(formatter_type, output_path = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/formatter/formatter_set.rb', line 48 def add_formatter(formatter_type, output_path = nil) if output_path dir_path = File.dirname(output_path) FileUtils.mkdir_p(dir_path) unless File.exist?(dir_path) output = File.open(output_path, 'w') else output = $stdout end self << formatter_class(formatter_type).new(output, @options) end |
#close_output_files ⇒ Object
60 61 62 63 64 |
# File 'lib/rubocop/formatter/formatter_set.rb', line 60 def close_output_files each do |formatter| formatter.output.close if formatter.output.is_a?(File) end end |
#file_finished(file, offenses) ⇒ Object
43 44 45 46 |
# File 'lib/rubocop/formatter/formatter_set.rb', line 43 def file_finished(file, offenses) each { |f| f.file_finished(file, offenses) } offenses end |
#file_started(file, options) ⇒ Object
37 38 39 40 41 |
# File 'lib/rubocop/formatter/formatter_set.rb', line 37 def file_started(file, ) @options = [:cli_options] @config_store = [:config_store] each { |f| f.file_started(file, ) } end |