diff options
| author | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-26 15:38:49 -0800 | 
|---|---|---|
| committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-26 15:38:49 -0800 | 
| commit | aef76d1e7120a16e0cace1ca89c327c70cbaddf3 (patch) | |
| tree | f08da969bc8289aed4d0d9ed0c95c637d6ae8f74 | |
| parent | 458b6a7fc905a23643fc0d26146e6bf230c9c472 (diff) | |
| parent | 3c6891593d84b83c70441b4c953080481bdcc4bf (diff) | |
| download | rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.tar.gz rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.tar.bz2 rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.zip | |
Merge remote branch 'fxn/master'
8 files changed, 0 insertions, 264 deletions
| diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index ff7bc3b34e..bef93dd0f8 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -1,6 +1,5 @@  require 'set'  require 'active_support/json' -require 'active_support/core_ext/object/extending'  require 'active_support/core_ext/object/returning'  module ActionView diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index 8cbb72dc83..bf02e5a864 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -1,5 +1,4 @@  require 'abstract_unit' -require 'active_support/core_ext/class/removal'  module AbstractControllerTests    module Layouts diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 44ad6c8c08..62df7d8b82 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,4 +1,3 @@  require 'active_support/core_ext/class/attribute_accessors'  require 'active_support/core_ext/class/inheritable_attributes' -require 'active_support/core_ext/class/removal'  require 'active_support/core_ext/class/delegating_attributes' diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb deleted file mode 100644 index 652be4ed78..0000000000 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'active_support/core_ext/object/extending' -require 'active_support/core_ext/module/introspection' - -class Class #:nodoc: - -  def reachable? -    eval("defined?(::#{self}) && ::#{self}.equal?(self)") -  end - -  # Unassociates the class with its subclasses and removes the subclasses -  # themselves. -  # -  #   Integer.remove_subclasses # => [Bignum, Fixnum] -  #   Fixnum                    # => NameError: uninitialized constant Fixnum -  def remove_subclasses -    Object.remove_subclasses_of(self) -  end - -  # Returns an array with the names of the subclasses of +self+ as strings. -  # -  #   Integer.subclasses # => ["Bignum", "Fixnum"] -  def subclasses -    Object.subclasses_of(self).map { |o| o.to_s } -  end - -  # Removes the classes in +klasses+ from their parent module. -  # -  # Ordinary classes belong to some module via a constant. This method computes -  # that constant name from the class name and removes it from the module it -  # belongs to. -  # -  #   Object.remove_class(Integer) # => [Integer] -  #   Integer                      # => NameError: uninitialized constant Integer -  # -  # Take into account that in general the class object could be still stored -  # somewhere else. -  # -  #   i = Integer                  # => Integer -  #   Object.remove_class(Integer) # => [Integer] -  #   Integer                      # => NameError: uninitialized constant Integer -  #   i.subclasses                 # => ["Bignum", "Fixnum"] -  #   Fixnum.superclass            # => Integer -  def remove_class(*klasses) -    klasses.flatten.each do |klass| -      # Skip this class if there is nothing bound to this name -      next unless defined?(klass.name) -       -      basename = klass.to_s.split("::").last -      parent = klass.parent -       -      # Skip this class if it does not match the current one bound to this name -      next unless parent.const_defined?(basename) && klass = parent.const_get(basename) - -      parent.instance_eval { remove_const basename } unless parent == klass -    end -  end -end diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 04e8f06b3d..08e07a5b24 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -4,7 +4,6 @@ require 'active_support/core_ext/object/duplicable'  require 'active_support/core_ext/object/try'  require 'active_support/core_ext/object/conversions' -require 'active_support/core_ext/object/extending'  require 'active_support/core_ext/object/instance_variables'  require 'active_support/core_ext/object/metaclass'  require 'active_support/core_ext/object/misc' diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb deleted file mode 100644 index b8b6970382..0000000000 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'active_support/core_ext/class/removal' -require 'active_support/core_ext/object/blank' - -class Class -  # Rubinius -  if defined?(Class.__subclasses__) -    def descendents -      subclasses = [] -      __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents } -      subclasses -    end -  else -    # MRI -    begin -      ObjectSpace.each_object(Class.new) {} - -      def descendents -        subclasses = [] -        ObjectSpace.each_object(class << self; self; end) do |k| -          subclasses << k unless k == self -        end -        subclasses -      end -    # JRuby -    rescue StandardError -      def descendents -        subclasses = [] -        ObjectSpace.each_object(Class) do |k| -          subclasses << k if k < self -        end -        subclasses.uniq! -        subclasses -      end -    end -  end -end - -class Object -  def remove_subclasses_of(*superclasses) #:nodoc: -    Class.remove_class(*subclasses_of(*superclasses)) -  end - -  # Exclude this class unless it's a subclass of our supers and is defined. -  # We check defined? in case we find a removed class that has yet to be -  # garbage collected. This also fails for anonymous classes -- please -  # submit a patch if you have a workaround. -  def subclasses_of(*superclasses) #:nodoc: -    subclasses = [] -    superclasses.each do |klass| -      subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} -    end -    subclasses -  end - -  def extended_by #:nodoc: -    ancestors = class << self; ancestors end -    ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] -  end - -  def extend_with_included_modules_from(object) #:nodoc: -    object.extended_by.each { |mod| extend mod } -  end -end diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb deleted file mode 100644 index bb4eb3c7d5..0000000000 --- a/activesupport/test/core_ext/class_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'abstract_unit' -require 'active_support/core_ext/class' - -class A -end - -module X -  class B -  end -end - -module Y -  module Z -    class C -    end -  end -end - -class ClassTest < Test::Unit::TestCase -  def test_removing_class_in_root_namespace -    assert A.is_a?(Class) -    Class.remove_class(A) -    assert_raise(NameError) { A.is_a?(Class) } -  end - -  def test_removing_class_in_one_level_namespace -    assert X::B.is_a?(Class) -    Class.remove_class(X::B) -    assert_raise(NameError) { X::B.is_a?(Class) } -  end - -  def test_removing_class_in_two_level_namespace -    assert Y::Z::C.is_a?(Class) -    Class.remove_class(Y::Z::C) -    assert_raise(NameError) { Y::Z::C.is_a?(Class) } -  end -   -  def test_retrieving_subclasses -    @parent   = eval("class D; end; D") -    @sub      = eval("class E < D; end; E") -    @subofsub = eval("class F < E; end; F") -    assert_equal 2, @parent.subclasses.size -    assert_equal [@subofsub.to_s], @sub.subclasses -    assert_equal [], @subofsub.subclasses -    assert_equal [@sub.to_s, @subofsub.to_s].sort, @parent.subclasses.sort -  end -end diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index e6fbdb637b..0b2a9c418e 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,7 +1,6 @@  require 'abstract_unit'  require 'active_support/time'  require 'active_support/core_ext/object' -require 'active_support/core_ext/class/removal'  class ClassA; end  class ClassB < ClassA; end @@ -40,99 +39,7 @@ class Foo    include Bar  end -class ClassExtTest < Test::Unit::TestCase -  def test_methods -    assert defined?(ClassB) -    assert defined?(ClassC) -    assert defined?(ClassD) - -    ClassA.remove_subclasses - -    assert !defined?(ClassB) -    assert !defined?(ClassC) -    assert !defined?(ClassD) -  end - -  def test_subclasses_of -    cj = ClassJ -    assert_equal [ClassJ], Object.subclasses_of(ClassI) -    ClassI.remove_subclasses -    assert_equal [], Object.subclasses_of(ClassI) -  ensure -    Object.const_set :ClassJ, cj -  end - -  def test_subclasses_of_should_find_nested_classes -    assert Object.subclasses_of(ClassK).include?(Nested::ClassL) -  end - -  def test_subclasses_of_should_not_return_removed_classes -    # First create the removed class -    old_class = Nested.class_eval { remove_const :ClassL } -    new_class = Class.new(ClassK) -    Nested.const_set :ClassL, new_class -    assert_equal "Nested::ClassL", new_class.name # Sanity check - -    subclasses = Object.subclasses_of(ClassK) -    assert subclasses.include?(new_class) -    assert ! subclasses.include?(old_class) -  ensure -    Nested.const_set :ClassL, old_class unless defined?(Nested::ClassL) -  end -   -  def test_subclasses_of_should_not_trigger_const_missing -    const_missing = false -    Nested.on_const_missing { const_missing = true } -     -    subclasses = Object.subclasses_of ClassK -    assert !const_missing -    assert_equal [ Nested::ClassL ], subclasses -     -    removed = Nested.class_eval { remove_const :ClassL }  # keep it in memory -    subclasses = Object.subclasses_of ClassK -    assert !const_missing -    assert subclasses.empty? -  ensure -    Nested.const_set :ClassL, removed unless defined?(Nested::ClassL) -  end -   -  def test_subclasses_of_with_multiple_roots -    classes = Object.subclasses_of(ClassI, ClassK) -    assert_equal %w(ClassJ Nested::ClassL), classes.collect(&:to_s).sort -  end - -  def test_subclasses_of_doesnt_find_anonymous_classes -    assert_equal [], Object.subclasses_of(Foo) -    bar = Class.new(Foo) -    assert_nothing_raised do -      assert_equal [bar], Object.subclasses_of(Foo) -    end -  end -end -  class ObjectTests < Test::Unit::TestCase -  def test_extended_by -    foo = Foo.new -    assert foo.extended_by.include?(Bar) -    foo.extend(Baz) -    assert(([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}") -  end - -  def test_extend_with_included_modules_from -    foo, object = Foo.new, Object.new -    assert !object.respond_to?(:bar) -    assert !object.respond_to?(:baz) - -    object.extend_with_included_modules_from(foo) -    assert object.respond_to?(:bar) -    assert !object.respond_to?(:baz) - -    foo.extend(Baz) -    object.extend_with_included_modules_from(foo) -    assert object.respond_to?(:bar) -    assert object.respond_to?(:baz) -  end -    class DuckTime      def acts_like_time?        true | 
