1
0

inheritance_tracking.rb 452 B

123456789101112131415161718192021222324
  1. module InheritanceTracking
  2. extend ActiveSupport::Concern
  3. module ClassMethods
  4. def inherited(subclass)
  5. @subclasses ||= []
  6. @subclasses << subclass
  7. @subclasses.uniq!
  8. super
  9. end
  10. def subclasses
  11. @subclasses
  12. end
  13. def with_subclasses(*subclasses)
  14. original_subclasses = @subclasses
  15. @subclasses = subclasses.flatten
  16. yield
  17. ensure
  18. @subclasses = original_subclasses
  19. end
  20. end
  21. end