Class: Warnings::ParserFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/warnings/parser/parser_factory.rb

Overview

Factory class for supported parsers.

Constant Summary collapse

ERROR_NOT_SUPPORTED =
'Parser \'%s\' not supported.'.freeze
AVAILABLE_PARSERS =
{
  bandit: BanditParser,
  pylint: PylintParser,
  rubocop: RubocopParser
}.freeze

Class Method Summary collapse

Class Method Details

.create(type) ⇒ Parser

Create a new parser implementation.

Parameters:

  • type (Symbol)

    A key symbol / name to identify the parser.

Returns:

Raises:

  • If no implementation could be found for the key.



20
21
22
23
24
25
26
27
# File 'lib/warnings/parser/parser_factory.rb', line 20

def self.create(type)
  key = type
  key = key.to_sym if key.respond_to?(:to_sym)
  parser = AVAILABLE_PARSERS[key]
  raise(format(ERROR_NOT_SUPPORTED, key)) if parser.nil?

  parser.new
end