File: active_support/core_ext/load_error.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#27
  module: CoreExtensions#28
  module: LoadErrorExtensions#29
  module: LoadErrorClassMethods#30
has properties
method: new / 1 #31
  class: MissingSourceFile#1
inherits from
  LoadError ( Builtin-Module )
has properties
attribute: path [R] #2
method: initialize / 2 #3
method: is_missing? / 1 #8
class method: from_message / 1 #12
constant: REGEXPS #20

Class Hierarchy

Code

   1  class MissingSourceFile < LoadError #:nodoc:
   2    attr_reader :path
   3    def initialize(message, path)
   4      super(message)
   5      @path = path
   6    end
   7 
   8    def is_missing?(path)
   9      path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
  10    end
  11 
  12    def self.from_message(message)
  13      REGEXPS.each do |regexp, capture|
  14        match = regexp.match(message)
  15        return MissingSourceFile.new(message, match[capture]) unless match.nil?
  16      end
  17      nil
  18    end
  19 
  20    REGEXPS = [
  21      [/^no such file to load -- (.+)$/i, 1],
  22      [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
  23      [/^Missing API definition file in (.+)$/i, 1]
  24    ] unless defined?(REGEXPS)
  25  end
  26 
  27  module ActiveSupport #:nodoc:
  28    module CoreExtensions #:nodoc:
  29      module LoadErrorExtensions #:nodoc:
  30        module LoadErrorClassMethods #:nodoc:
  31          def new(*args)
  32            (self == LoadError && MissingSourceFile.from_message(args.first)) || super
  33          end
  34        end
  35        ::LoadError.extend(LoadErrorClassMethods)
  36      end
  37    end
  38  end