Changeset 4754
- Timestamp:
- 08/13/06 03:29:04 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (2 diffs)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4728 r4754 1 1 *SVN* 2 2 3 <<<<<<< .mine 3 * Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. [Nicholas Seckar] 4 4 5 * Replace Reloadable with improvements to the Dependencies mechanism. [Nicholas Seckar] 5 6 6 =======7 7 * DateTime#to_time gives hour/minute/second resolution. #5747 [jon.evans@pobox.com] 8 8 … … 13 13 attr_internal :foo 14 14 15 >>>>>>> .r472716 15 * Raise fully qualified names upon name errors. #5533 [lars@pinds.com, Nicholas Seckar] 17 16 trunk/activesupport/lib/active_support/dependencies.rb
r4730 r4754 27 27 self.autoload_paths = [] 28 28 29 # An array of qualified constant names that have been loaded. Adding a name to 30 # this array will cause it to be unloaded the next time Dependencies are cleared. 29 31 mattr_accessor :autoloaded_constants 30 32 self.autoloaded_constants = [] 33 34 # Set to true to enable logging of const_missing and file loads 35 mattr_accessor :log_activity 36 self.log_activity = false 31 37 32 38 def load? … … 46 52 47 53 def clear 54 log_call 48 55 loaded.clear 49 56 remove_autoloaded_constants! … … 51 58 52 59 def require_or_load(file_name, const_path = nil) 60 log_call file_name, const_path 53 61 file_name = $1 if file_name =~ /^(.*)\.rb$/ 54 62 expanded = File.expand_path(file_name) … … 60 68 61 69 if load? 70 log "loading #{file_name}" 62 71 begin 63 72 # Enable warnings iff this file has not been loaded before and … … 76 85 end 77 86 else 87 log "requiring #{file_name}" 78 88 require file_name 79 89 end … … 133 143 # +autoloadable_constants_for_path+ for more details. 134 144 def load_file(path, const_paths = autoloadable_constants_for_path(path)) 145 log_call path, const_paths 146 135 147 const_paths = [const_paths].compact unless const_paths.is_a? Array 136 148 undefined_before = const_paths.reject(&method(:qualified_const_defined?)) … … 138 150 load path 139 151 140 autoloaded_constants.concat const_paths.select(&method(:qualified_const_defined?)) 152 newly_defined_paths = const_paths.select(&method(:qualified_const_defined?)) 153 autoloaded_constants.concat newly_defined_paths 141 154 autoloaded_constants.uniq! 155 log "loading #{path} defined #{newly_defined_paths * ', '}" unless newly_defined_paths.empty? 142 156 end 143 157 … … 152 166 # using const_missing. 153 167 def load_missing_constant(from_mod, const_name) 168 log_call from_mod, const_name 169 154 170 qualified_name = qualified_name_for from_mod, const_name 155 171 path_suffix = qualified_name.underscore … … 194 210 parent = (names[0..-2] * '::').constantize 195 211 end 212 log "removing constant #{const}" 196 213 parent.send :remove_const, names.last 197 214 true … … 227 244 when Module then desc.name 228 245 else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}" 246 end 247 end 248 249 def log_call(*args) 250 arg_str = args.collect(&:inspect) * ', ' 251 /in `([a-z_\?\!]+)'/ =~ caller(1).first 252 selector = $1 || '<unknown>' 253 log "called #{selector}(#{arg_str})" 254 end 255 256 def log(msg) 257 if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity 258 RAILS_DEFAULT_LOGGER.debug "Dependencies: #{msg}" 229 259 end 230 260 end