Class: Packwerk::Parsers::Factory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/packwerk/parsers/factory.rb

Instance Method Summary collapse

Constructor Details

#initializeFactory

: -> void



23
24
25
26
27
# File 'lib/packwerk/parsers/factory.rb', line 23

def initialize
  @ruby_parser = nil #: ParserInterface?
  @erb_parser = nil #: ParserInterface?
  @erb_parser_class = nil #: Class[top]?
end

Instance Method Details

#erb_parser_classObject

: -> Class



41
42
43
# File 'lib/packwerk/parsers/factory.rb', line 41

def erb_parser_class
  @erb_parser_class ||= Erb
end

#erb_parser_class=(klass) ⇒ Object

: (Class? klass) -> void



46
47
48
49
# File 'lib/packwerk/parsers/factory.rb', line 46

def erb_parser_class=(klass)
  @erb_parser_class = klass
  @erb_parser = nil
end

#for_path(path) ⇒ Object

: (String path) -> ParserInterface?



30
31
32
33
34
35
36
37
38
# File 'lib/packwerk/parsers/factory.rb', line 30

def for_path(path)
  case path
  when RUBY_REGEX
    @ruby_parser ||= Ruby.new
  when ERB_REGEX
    erb_parser_class_ = erb_parser_class #: as untyped
    @erb_parser ||= erb_parser_class_.new
  end
end