Sha256: 468776ff3a1f4d4e091dbc246407d3f533f2f5b5ec670ac149556d81709009b7

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require_relative('../explicit_require')

module Bootsnap
  module LoadPathCache
    module PathScanner
      ALL_FILES = "/{,**/*/**/}*"
      REQUIRABLE_EXTENSIONS = [DOT_RB] + DL_EXTENSIONS
      NORMALIZE_NATIVE_EXTENSIONS = !DL_EXTENSIONS.include?(LoadPathCache::DOT_SO)
      ALTERNATIVE_NATIVE_EXTENSIONS_PATTERN = /\.(o|bundle|dylib)\z/

      BUNDLE_PATH = if Bootsnap.bundler?
        (Bundler.bundle_path.cleanpath.to_s << LoadPathCache::SLASH).freeze
      else
        ''
      end

      def self.call(path)
        path = path.to_s

        relative_slice = (path.size + 1)..-1
        # If the bundle path is a descendent of this path, we do additional
        # checks to prevent recursing into the bundle path as we recurse
        # through this path. We don't want to scan the bundle path because
        # anything useful in it will be present on other load path items.
        #
        # This can happen if, for example, the user adds '.' to the load path,
        # and the bundle path is '.bundle'.
        contains_bundle_path = BUNDLE_PATH.start_with?(path)

        dirs = []
        requirables = []

        Dir.glob(path + ALL_FILES).each do |absolute_path|
          next if contains_bundle_path && absolute_path.start_with?(BUNDLE_PATH)
          relative_path = absolute_path.slice(relative_slice)

          if File.directory?(absolute_path)
            dirs << relative_path
          elsif REQUIRABLE_EXTENSIONS.include?(File.extname(relative_path))
            requirables << relative_path
          end
        end

        [requirables, dirs]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
bootsnap-1.4.6-java lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.6 lib/bootsnap/load_path_cache/path_scanner.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/path_scanner.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.5-java lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.5 lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.4-java lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.4 lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.3-java lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.3 lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.2-java lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.2 lib/bootsnap/load_path_cache/path_scanner.rb
bootsnap-1.4.2.rc3 lib/bootsnap/load_path_cache/path_scanner.rb