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

Changeset 1331

Show
Ignore:
Timestamp:
05/19/05 19:17:08 (3 years ago)
Author:
david
Message:

Fixed Dependencies so all modules are able to load missing constants #1173 [Nicholas Seckar]

Files:

Legend:

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

    r1330 r1331  
    11*SVN* 
     2 
     3* Fixed Dependencies so all modules are able to load missing constants #1173 [Nicholas Seckar] 
    24 
    35* Fixed the Inflector to underscore strings containing numbers, so Area51Controller becomes area51_controller #1176 [Nicholas Seckar] 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r1125 r1331  
    168168Object.send(:define_method, :require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association) 
    169169 
     170class Module #:nodoc: 
     171  # Use const_missing to autoload associations so we don't have to 
     172  # require_association when using single-table inheritance. 
     173  def const_missing(class_id) 
     174    if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id) 
     175      return Object::Controllers.const_get(class_id) 
     176    end 
     177     
     178    begin 
     179      require_dependency(class_id.to_s.demodulize.underscore) 
     180      if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end 
     181    rescue LoadError => e 
     182      raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 
     183    end 
     184  end 
     185end 
     186 
    170187class Object #:nodoc: 
    171   class << self 
    172     # Use const_missing to autoload associations so we don't have to 
    173     # require_association when using single-table inheritance. 
    174     def const_missing(class_id) 
    175       if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id) 
    176         return Object::Controllers.const_get(class_id) 
    177       end 
    178  
    179       begin 
    180         require_dependency(class_id.to_s.demodulize.underscore) 
    181         if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end 
    182       rescue LoadError => e 
    183         raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) 
    184       end 
    185     end 
    186   end 
    187  
    188188  def load(file, *extras) 
    189189    begin super(file, *extras)