Skip to content
This repository
Browse code

make ActiveRecord::Base.subclasses a public method

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information...
commit f8eddcc7351c899088353aed21ee6e14ddb23ccf 1 parent 219c81b
authored August 28, 2009 wycats committed April 12, 2010
6  activerecord/lib/active_record/base.rb
@@ -1285,11 +1285,15 @@ def with_exclusive_scope(method_scoping = {}, &block)
1285 1285
           with_scope(method_scoping, :overwrite, &block)
1286 1286
         end
1287 1287
 
1288  
-        def subclasses #:nodoc:
  1288
+        # ActiveRecord::Base utilizes the inherited hook to know about new subclasses.
  1289
+        # You can access the list of currently loaded ActiveRecord::Base subclasses using this accessor.
  1290
+        def subclasses
1289 1291
           @@subclasses[self] ||= []
1290 1292
           @@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses }
1291 1293
         end
1292 1294
 
  1295
+        public :subclasses
  1296
+
1293 1297
         # Sets the default options for the model. The format of the
1294 1298
         # <tt>options</tt> argument is the same as in find.
1295 1299
         #
4  activerecord/test/cases/base_test.rb
@@ -2053,6 +2053,10 @@ def test_descends_from_active_record
2053 2053
     assert !SubStiPost.descends_from_active_record?
2054 2054
   end
2055 2055
 
  2056
+  def test_base_subclasses_is_public_method
  2057
+    assert ActiveRecord::Base.public_methods.include?("subclasses")
  2058
+  end
  2059
+
2056 2060
   def test_find_on_abstract_base_class_doesnt_use_type_condition
2057 2061
     old_class = LooseDescendant
2058 2062
     Object.send :remove_const, :LooseDescendant

0 notes on commit f8eddcc

Please sign in to comment.
Something went wrong with that request. Please try again.