Sha256: ce53fd76270d820afcfe82a445bc36b35884a258f087f77481f1c2397d81fa50

Contents?: true

Size: 686 Bytes

Versions: 3

Compression:

Stored size: 686 Bytes

Contents

# typed: true
# frozen_string_literal: true

require "singleton"

require "packwerk/parsers"

module Packwerk
  module Parsers
    class Factory
      include Singleton

      RUBY_REGEX = %r{
        # Although not important for regex, these are ordered from most likely to match to least likely.
        \.(rb|rake|builder|gemspec|ru)\Z
        |
        (Gemfile|Rakefile)\Z
      }x
      private_constant :RUBY_REGEX

      ERB_REGEX = /\.erb\Z/
      private_constant :ERB_REGEX

      def for_path(path)
        case path
        when RUBY_REGEX
          @ruby_parser ||= Ruby.new
        when ERB_REGEX
          @erb_parser ||= Erb.new
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
packwerk-1.0.2 lib/packwerk/parsers/factory.rb
packwerk-1.0.1 lib/packwerk/parsers/factory.rb
packwerk-1.0.0 lib/packwerk/parsers/factory.rb