Sha256: ad8213db8632409a8b873cd3966fa86f9720997f06ea8ede61a7e2848298ea8d

Contents?: true

Size: 839 Bytes

Versions: 6

Compression:

Stored size: 839 Bytes

Contents

require 'core_ext/deprecation/proxy_wrappers'

class LoadError
  REGEXPS = [
    /^no such file to load -- (.+)$/i,
    /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
    /^Missing API definition file in (.+)$/i,
    /^cannot load such file -- (.+)$/i,
  ]

  unless method_defined?(:path)
    # Returns the path which was unable to be loaded.
    def path
      @path ||= begin
        REGEXPS.find do |regex|
          message =~ regex
        end
        $1
      end
    end
  end

  # Returns true if the given path name (except perhaps for the ".rb"
  # extension) is the missing file which caused the exception to be raised.
  def is_missing?(location)
    location.sub(/\.rb$/, ''.freeze) == path.sub(/\.rb$/, ''.freeze)
  end
end

MissingSourceFile = CoreExt::Deprecation::DeprecatedConstantProxy.new('MissingSourceFile', 'LoadError')

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
core_ext-0.0.6 lib/core_ext/load_error.rb
core_ext-0.0.5 lib/core_ext/load_error.rb
core_ext-0.0.4 lib/core_ext/load_error.rb
core_ext-0.0.3 lib/core_ext/load_error.rb
core_ext-0.0.2 lib/core_ext/load_error.rb
core_ext-0.0.1 lib/core_ext/load_error.rb