mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add debugging logging to Dependencies.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4754 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
33406747d8
commit
440655e1fa
2 changed files with 33 additions and 4 deletions
|
@ -1,9 +1,9 @@
|
|||
*SVN*
|
||||
|
||||
<<<<<<< .mine
|
||||
* Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. [Nicholas Seckar]
|
||||
|
||||
* Replace Reloadable with improvements to the Dependencies mechanism. [Nicholas Seckar]
|
||||
|
||||
=======
|
||||
* DateTime#to_time gives hour/minute/second resolution. #5747 [jon.evans@pobox.com]
|
||||
|
||||
* attr_internal to support namespacing and deprecation. Like attr_* except backed by internally-named instance variable. Set attr_internal_naming_format to change the format from the default '@_%s'. [Jeremy Kemper]
|
||||
|
@ -12,7 +12,6 @@
|
|||
self.attr_internal_naming_format = '@%s__rofl'
|
||||
attr_internal :foo
|
||||
|
||||
>>>>>>> .r4727
|
||||
* Raise fully qualified names upon name errors. #5533 [lars@pinds.com, Nicholas Seckar]
|
||||
|
||||
* Add extention to obtain the missing constant from NameError instances. [Nicholas Seckar]
|
||||
|
|
|
@ -26,9 +26,15 @@ module Dependencies #:nodoc:
|
|||
mattr_accessor :autoload_paths
|
||||
self.autoload_paths = []
|
||||
|
||||
# An array of qualified constant names that have been loaded. Adding a name to
|
||||
# this array will cause it to be unloaded the next time Dependencies are cleared.
|
||||
mattr_accessor :autoloaded_constants
|
||||
self.autoloaded_constants = []
|
||||
|
||||
# Set to true to enable logging of const_missing and file loads
|
||||
mattr_accessor :log_activity
|
||||
self.log_activity = false
|
||||
|
||||
def load?
|
||||
mechanism == :load
|
||||
end
|
||||
|
@ -45,11 +51,13 @@ module Dependencies #:nodoc:
|
|||
end
|
||||
|
||||
def clear
|
||||
log_call
|
||||
loaded.clear
|
||||
remove_autoloaded_constants!
|
||||
end
|
||||
|
||||
def require_or_load(file_name, const_path = nil)
|
||||
log_call file_name, const_path
|
||||
file_name = $1 if file_name =~ /^(.*)\.rb$/
|
||||
expanded = File.expand_path(file_name)
|
||||
return if loaded.include?(expanded)
|
||||
|
@ -59,6 +67,7 @@ module Dependencies #:nodoc:
|
|||
loaded << expanded
|
||||
|
||||
if load?
|
||||
log "loading #{file_name}"
|
||||
begin
|
||||
# Enable warnings iff this file has not been loaded before and
|
||||
# warnings_on_first_load is set.
|
||||
|
@ -75,6 +84,7 @@ module Dependencies #:nodoc:
|
|||
raise
|
||||
end
|
||||
else
|
||||
log "requiring #{file_name}"
|
||||
require file_name
|
||||
end
|
||||
|
||||
|
@ -132,13 +142,17 @@ module Dependencies #:nodoc:
|
|||
# of names that the file at +path+ may define. See
|
||||
# +autoloadable_constants_for_path+ for more details.
|
||||
def load_file(path, const_paths = autoloadable_constants_for_path(path))
|
||||
log_call path, const_paths
|
||||
|
||||
const_paths = [const_paths].compact unless const_paths.is_a? Array
|
||||
undefined_before = const_paths.reject(&method(:qualified_const_defined?))
|
||||
|
||||
load path
|
||||
|
||||
autoloaded_constants.concat const_paths.select(&method(:qualified_const_defined?))
|
||||
newly_defined_paths = const_paths.select(&method(:qualified_const_defined?))
|
||||
autoloaded_constants.concat newly_defined_paths
|
||||
autoloaded_constants.uniq!
|
||||
log "loading #{path} defined #{newly_defined_paths * ', '}" unless newly_defined_paths.empty?
|
||||
end
|
||||
|
||||
# Return the constant path for the provided parent and constant name.
|
||||
|
@ -151,6 +165,8 @@ module Dependencies #:nodoc:
|
|||
# it is not possible to laod the constant into from_mod, try its parent module
|
||||
# using const_missing.
|
||||
def load_missing_constant(from_mod, const_name)
|
||||
log_call from_mod, const_name
|
||||
|
||||
qualified_name = qualified_name_for from_mod, const_name
|
||||
path_suffix = qualified_name.underscore
|
||||
name_error = NameError.new("uninitialized constant #{qualified_name}")
|
||||
|
@ -193,6 +209,7 @@ module Dependencies #:nodoc:
|
|||
else
|
||||
parent = (names[0..-2] * '::').constantize
|
||||
end
|
||||
log "removing constant #{const}"
|
||||
parent.send :remove_const, names.last
|
||||
true
|
||||
end
|
||||
|
@ -229,6 +246,19 @@ protected
|
|||
end
|
||||
end
|
||||
|
||||
def log_call(*args)
|
||||
arg_str = args.collect(&:inspect) * ', '
|
||||
/in `([a-z_\?\!]+)'/ =~ caller(1).first
|
||||
selector = $1 || '<unknown>'
|
||||
log "called #{selector}(#{arg_str})"
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity
|
||||
RAILS_DEFAULT_LOGGER.debug "Dependencies: #{msg}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Object.send(:define_method, :require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load)
|
||||
|
|
Loading…
Reference in a new issue