module Sequel::Plugins::Subclasses

  1. lib/sequel/plugins/subclasses.rb

The Subclasses plugin keeps track of all subclasses of the current model class. Direct subclasses are available via the subclasses method, and all descendent classes are available via the descendents method.

c =
c.plugin :subclasses
sc1 =
sc2 =
ssc1 =
c.subclasses    # [sc1, sc2]
sc1.subclasses  # [ssc1]
sc2.subclasses  # []
ssc1.subclasses # []
c.descendents   # [sc1, ssc1, sc2]

You can provide a block when loading the plugin, and it will be called with each subclass created:

a = []
Sequel::Model.plugin(:subclasses){|sc| a << sc}
class A < Sequel::Model; end
class B < Sequel::Model; end
a # => [A, B]


Public Class

  1. apply

Public Class methods

apply (model, &block)

Initialize the subclasses instance variable for the model.

[show source]
# File lib/sequel/plugins/subclasses.rb, line 30
def self.apply(model, &block)
  model.instance_variable_set(:@subclasses, [])
  model.instance_variable_set(:@on_subclass, block)