From 7a43a05a2b236123329be3198c149c8e894b0450 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Thu, 2 Feb 2006 04:54:07 +0000 Subject: Further improvements to reloading code git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3519 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/class/removal.rb | 14 +++++--------- .../lib/active_support/core_ext/module/inclusion.rb | 4 ---- activesupport/lib/active_support/dependencies.rb | 8 -------- activesupport/lib/active_support/reloadable.rb | 13 +++++++++++++ 4 files changed, 18 insertions(+), 21 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb index 8fc4d728b3..468c77d81b 100644 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ b/activesupport/lib/active_support/core_ext/class/removal.rb @@ -7,15 +7,11 @@ class Class #:nodoc: Object.subclasses_of(self).map { |o| o.to_s } end - def remove_class(klass) - if klass.to_s.include? "::" - modules = klass.to_s.split("::") - final_klass = modules.pop - - final_module = modules.inject(Object) { |final_type, part| final_type.const_get(part) } - final_module.send(:remove_const, final_klass) rescue nil - else - Object.send(:remove_const, klass.to_s) rescue nil + def remove_class(*klasses) + klasses.each do |klass| + basename = klass.to_s.split("::").last + parent = klass.parent + parent.send :remove_const, basename unless parent == klass end end end \ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/module/inclusion.rb b/activesupport/lib/active_support/core_ext/module/inclusion.rb index 124c4551bc..efc00d6f28 100644 --- a/activesupport/lib/active_support/core_ext/module/inclusion.rb +++ b/activesupport/lib/active_support/core_ext/module/inclusion.rb @@ -1,8 +1,4 @@ class Module - def remove_classes_including - included_in_classes.each { |klass| Class.remove_class(klass) } - end - def included_in_classes classes = [] ObjectSpace.each_object(Class) { |k| classes << k if k.included_modules.include?(self) } diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 37a3f4acb3..7f73f9bf40 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -159,14 +159,6 @@ module Dependencies #:nodoc: def load_file!(file_path) require_dependency(file_path) end - - # Erase all items in this module - def clear! - constants.each do |name| - Object.send(:remove_const, name) if Object.const_defined?(name) && Object.const_get(name).object_id == self.const_get(name).object_id - self.send(:remove_const, name) - end - end end # This object defines a path from which Constants can be loaded. diff --git a/activesupport/lib/active_support/reloadable.rb b/activesupport/lib/active_support/reloadable.rb index fca397afeb..49e6442a37 100644 --- a/activesupport/lib/active_support/reloadable.rb +++ b/activesupport/lib/active_support/reloadable.rb @@ -1,4 +1,17 @@ # Classes that include this module will automatically be reloaded # by the Rails dispatcher when Dependencies.mechanism = :load. module Reloadable + class << self + def included(base) #nodoc: + if base.is_a?(Class) && ! base.respond_to?(:reloadable?) + class << base + define_method(:reloadable?) { true } + end + end + end + + def reloadable_classes + included_in_classes.select { |klass| klass.reloadable? } + end + end end \ No newline at end of file -- cgit v1.2.3