Commit Graph

9 Commits

Author SHA1 Message Date
Jean Boussier cb82f5f0a4 Fix DescendantTracker.clear on Ruby 3.1
Previously I assumed it was useless, however I was wrong.

The method is called by the reloader to give the illusion that
the GC is precise. Meaning a class that will be unloaded is
immediately made invisible without waiting for it to be garbage collected.

This is easy to do up to Ruby 3.0 because `DescendantTracker` keeps
a map of all tracked classes.

However on 3.1 we need to use the inverse strategy, we keep a WeakMap
of all the classes we cleared, and we filter the return value of `descendants`
and `subclasses`.

Since `clear` is private API and is only used when reloading is enabled,
to reduce the performance impact in production mode, we entirely remove
this behavior when `config.cache_classes` is enabled.
2021-11-25 17:32:52 +01:00
Jean Boussier ffae3bd8d6 Refactor DescendantsTracker to leverage native Class#descendants on Ruby 3.1 2021-10-28 10:46:42 +02:00
Xavier Noria 340b39ea31 Remove autoloading logic from AS::DescendantsTracker
The descendants tracker is a generic tracker that you can use anywhere.
In particular, outside Rails applications.

Should provide API to clear only a subset of classes, but in my view
should know nothing about autoloading. That is a concern of client code.
2021-08-23 00:24:26 +02:00
Rolf Timmermans 76e4e2fa46 Refactored AS::DescendantsTracker test cases so they can be tested without AS::Dependencies. 2011-03-13 17:04:01 +01:00
José Valim a5dda97602 Define a convention for descendants and subclasses.
The former should be symmetric with ancestors and include all children. However, it should not include self since ancestors + descendants should not have duplicated. The latter is symmetric to superclass in the sense it only includes direct children.

By adopting a convention, we expect to have less conflict with other frameworks, as Datamapper. For this moment, to ensure ActiveModel::Validations can be used with Datamapper, we should always call ActiveSupport::DescendantsTracker.descendants(self) internally instead of self.descendants avoiding conflicts.
2010-07-05 13:01:27 +02:00
Xavier Noria 69fec3ab3f adds parens to silence a warning in the test suite of AS 2010-06-20 23:29:37 +02:00
José Valim d430db9fd4 Remove descendants warning while executing tests. 2010-06-19 17:16:11 +02:00
José Valim a2b7fcb07c Change callbacks to automatically include DescendantsTracker and rename descendents to descendants. 2010-06-19 16:58:15 +02:00
José Valim 8db8c6f4ce Add ActiveSupport::DescendantsTracker. 2010-06-19 16:44:35 +02:00