Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2771

Show
Ignore:
Timestamp:
10/27/05 17:40:48 (3 years ago)
Author:
ulysses
Message:

When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r2746 r2771  
    11*SVN* 
     2 
     3* When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present. [Nicholas Seckar] 
    24 
    35* Added petabytes and exebytes to numeric extensions #2397 [timct@mac.com] 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r2440 r2771  
    189189    end 
    190190     
     191    file_name = class_id.to_s.demodulize.underscore 
    191192    begin 
    192       require_dependency(class_id.to_s.demodulize.underscore) 
    193       if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end 
    194     rescue LoadError => e 
    195       begin 
    196         rails_original_const_missing(class_id) 
    197       rescue Exception 
    198         raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 
    199       end 
     193      require_dependency(file_name) 
     194      raise NameError.new("uninitialized constant #{class_id}") unless Object.const_defined?(class_id) 
     195      return Object.const_get(class_id) 
     196    rescue MissingSourceFile => e 
     197      # Convert the exception to a NameError only if the file we are looking for is the missing one. 
     198      raise unless e.path == "#{file_name}.rb" 
     199      raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 
    200200    end 
    201201  end