Sha256: 8704f0eab2a926b5c0a824c8a5f7fa27f762f52f0edc90ff0631c57cb9ddec73

Contents?: true

Size: 950 Bytes

Versions: 9

Compression:

Stored size: 950 Bytes

Contents

class MissingSourceFile < LoadError #:nodoc:
  attr_reader :path
  def initialize(message, path)
    super(message)
    @path = path
  end

  def is_missing?(path)
    path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
  end
  
  def self.from_message(message)
    REGEXPS.each do |regexp, capture|
      match = regexp.match(message)
      return MissingSourceFile.new(message, match[capture]) unless match.nil?
    end
    nil
  end
  
  REGEXPS = [
    [/^no such file to load -- (.+)$/i, 1],
    [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
    [/^Missing API definition file in (.+)$/i, 1]
  ]
end

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module LoadErrorExtensions #:nodoc:
      module LoadErrorClassMethods #:nodoc:
        def new(*args)
          (self == LoadError && MissingSourceFile.from_message(args.first)) || super
        end
      end
      ::LoadError.extend(LoadErrorClassMethods)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activesupport-1.2.1 lib/active_support/core_ext/load_error.rb
activesupport-1.2.4 lib/active_support/core_ext/load_error.rb
activesupport-1.1.0 lib/active_support/core_ext/load_error.rb
activesupport-1.1.1 lib/active_support/core_ext/load_error.rb
activesupport-1.2.2 lib/active_support/core_ext/load_error.rb
activesupport-1.2.3 lib/active_support/core_ext/load_error.rb
activesupport-1.2.5 lib/active_support/core_ext/load_error.rb
activesupport-1.3.0 lib/active_support/core_ext/load_error.rb
activesupport-1.3.1 lib/active_support/core_ext/load_error.rb