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

Changeset 5303

Show
Ignore:
Timestamp:
10/14/06 20:29:05 (2 years ago)
Author:
ulysses
Message:

Undo accidental commit

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/dependencies.rb

    r5302 r5303  
    3939  self.autoloaded_constants = [] 
    4040   
    41   # An array of constant names that need to be unloaded on every request. Used 
    42   # to allow arbitrary constants to be marked for unloading. 
    43   mattr_accessor :explicitly_unloadable_constants 
    44   self.explicitly_unloadable_constants = [] 
    45    
    4641  # Set to true to enable logging of const_missing and file loads 
    4742  mattr_accessor :log_activity 
     
    6661    log_call 
    6762    loaded.clear 
    68     remove_unloadable_constants! 
     63    remove_autoloaded_constants! 
    6964  end 
    7065 
     
    258253  end 
    259254   
    260   # Remove the constants that have been autoloaded, and those that have been 
    261   # marked for unloading. 
    262   def remove_unloadable_constants! 
    263     autoloaded_constants.each { |const| remove_constant const } 
    264     autoloaded_constants.clear 
    265     explicitly_unloadable_constants.each { |const| remove_constant const } 
     255  # Remove the constants that have been autoloaded. 
     256  def remove_autoloaded_constants! 
     257    until autoloaded_constants.empty? 
     258      const = autoloaded_constants.shift 
     259      next unless qualified_const_defined? const 
     260      names = const.split('::') 
     261      if names.size == 1 || names.first.empty? # It's under Object 
     262        parent = Object 
     263      else 
     264        parent = (names[0..-2] * '::').constantize 
     265      end 
     266      log "removing constant #{const}" 
     267      parent.send :remove_const, names.last 
     268      true 
     269    end 
    266270  end 
    267271   
     
    271275    return false unless qualified_const_defined? name 
    272276    return autoloaded_constants.include?(name) 
    273   end 
    274    
    275   # Will the provided constant descriptor be unloaded? 
    276   def will_unload?(const_desc) 
    277     autoloaded?(desc) || 
    278       explicitly_unloadable_constants.include?(const_desc.to_constant_name) 
    279   end 
    280    
    281   # Mark the provided constant name for unloading. This constant will be 
    282   # unloaded on each request, not just the next one. 
    283   def mark_for_unload(const_desc) 
    284     name = const_desc.to_constant_name 
    285     unless explicitly_unloadable_constants.include? name 
    286       explicitly_unloadable_constants << name 
    287     end 
    288277  end 
    289278   
     
    310299      else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}" 
    311300    end 
    312   end 
    313    
    314   def remove_constant(const) 
    315     return false unless qualified_const_defined? const 
    316      
    317     names = const.split('::') 
    318     if names.size == 1 || names.first.empty? # It's under Object 
    319       parent = Object 
    320     else 
    321       parent = (names[0..-2] * '::').constantize 
    322     end 
    323      
    324     log "removing constant #{const}" 
    325     parent.send :remove_const, names.last 
    326     return true 
    327301  end 
    328302