vendor/rails/activesupport/lib/active_support/dependencies.rb in radiant-0.6.4 vs vendor/rails/activesupport/lib/active_support/dependencies.rb in radiant-0.6.5
- old
+ new
@@ -1,9 +1,9 @@
require 'set'
-require File.dirname(__FILE__) + '/core_ext/module/attribute_accessors'
-require File.dirname(__FILE__) + '/core_ext/load_error'
-require File.dirname(__FILE__) + '/core_ext/kernel'
+require 'active_support/core_ext/module/attribute_accessors'
+require 'active_support/core_ext/load_error'
+require 'active_support/core_ext/kernel'
module Dependencies #:nodoc:
extend self
# Should we turn on Ruby warnings on the first load of dependent files?
@@ -112,11 +112,11 @@
# Is the provided constant path defined?
def qualified_const_defined?(path)
raise NameError, "#{path.inspect} is not a valid constant name!" unless
/^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path
- names = path.split('::')
+ names = path.to_s.split('::')
names.shift if names.first.empty?
# We can't use defined? because it will invoke const_missing for the parent
# of the name we are checking.
names.inject(Object) do |mod, name|
@@ -214,11 +214,11 @@
mod_name = to_constant_name mod
(%w(Object Kernel).include? mod_name) ? name.to_s : "#{mod_name}::#{name}"
end
# Load the constant named +const_name+ which is missing from +from_mod+. If
- # it is not possible to laod the constant into from_mod, try its parent module
+ # it is not possible to load 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
if from_mod == Kernel
if ::Object.const_defined?(const_name)
@@ -227,18 +227,18 @@
else
log "Substituting Object for Kernel"
from_mod = Object
end
end
-
+
# If we have an anonymous module, all we can do is attempt to load from Object.
- from_mod = Object if from_mod.name.empty?
-
+ from_mod = Object if from_mod.name.blank?
+
unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
-
+
raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
name_error = NameError.new("uninitialized constant #{qualified_name}")
@@ -381,50 +381,49 @@
end
end
class LoadingModule #:nodoc:
# Old style environment.rb referenced this method directly. Please note, it doesn't
- # actualy *do* anything any more.
+ # actually *do* anything any more.
def self.root(*args)
if defined?(RAILS_DEFAULT_LOGGER)
RAILS_DEFAULT_LOGGER.warn "Your environment.rb uses the old syntax, it may not continue to work in future releases."
RAILS_DEFAULT_LOGGER.warn "For upgrade instructions please see: http://manuals.rubyonrails.com/read/book/19"
end
end
end
-protected
-
# Convert the provided const desc to a qualified constant name (as a string).
# A module, class, symbol, or string may be provided.
- def to_constant_name(desc)
+ def to_constant_name(desc) #:nodoc:
name = case desc
when String then desc.starts_with?('::') ? desc[2..-1] : desc
when Symbol then desc.to_s
when Module
raise ArgumentError, "Anonymous modules have no name to be referenced by" if desc.name.blank?
desc.name
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
end
end
-
- def remove_constant(const)
+
+ def remove_constant(const) #:nodoc:
return false unless qualified_const_defined? const
-
+
const = $1 if /\A::(.*)\Z/ =~ const.to_s
- names = const.split('::')
+ names = const.to_s.split('::')
if names.size == 1 # It's under Object
parent = Object
else
parent = (names[0..-2] * '::').constantize
end
-
+
log "removing constant #{const}"
- parent.send :remove_const, names.last
+ parent.instance_eval { remove_const names.last }
return true
end
-
+
+protected
def log_call(*args)
arg_str = args.collect(&:inspect) * ', '
/in `([a-z_\?\!]+)'/ =~ caller(1).first
selector = $1 || '<unknown>'
log "called #{selector}(#{arg_str})"
@@ -436,13 +435,15 @@
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)
-Object.send(:define_method, :require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency)
-Object.send(:define_method, :require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association)
+Object.instance_eval do
+ define_method(:require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load)
+ define_method(:require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency)
+ define_method(:require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association)
+end
class Module #:nodoc:
# Rename the original handler so we can chain it to the new one
alias :rails_original_const_missing :const_missing
@@ -457,42 +458,42 @@
end
end
class Class
- def const_missing(class_id)
+ def const_missing(const_name)
if [Object, Kernel].include?(self) || parent == self
super
else
begin
begin
- Dependencies.load_missing_constant self, class_id
+ Dependencies.load_missing_constant self, const_name
rescue NameError
- parent.send :const_missing, class_id
+ parent.send :const_missing, const_name
end
rescue NameError => e
# Make sure that the name we are missing is the one that caused the error
- parent_qualified_name = Dependencies.qualified_name_for parent, class_id
+ parent_qualified_name = Dependencies.qualified_name_for parent, const_name
raise unless e.missing_name? parent_qualified_name
- qualified_name = Dependencies.qualified_name_for self, class_id
+ qualified_name = Dependencies.qualified_name_for self, const_name
raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e)
end
end
end
end
-class Object #:nodoc:
+class Object
alias_method :load_without_new_constant_marking, :load
- def load(file, *extras)
+ def load(file, *extras) #:nodoc:
Dependencies.new_constants_in(Object) { super(file, *extras) }
rescue Exception => exception # errors from loading file
exception.blame_file! file
raise
end
- def require(file, *extras)
+ def require(file, *extras) #:nodoc:
Dependencies.new_constants_in(Object) { super(file, *extras) }
rescue Exception => exception # errors from required file
exception.blame_file! file
raise
end