Module: Sequel::Plugins::Subclasses::ClassMethods

Defined in:
lib/sequel/plugins/subclasses.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_subclassObject (readonly)

Callable object that should be called with every descendent class created.



39
40
41
# File 'lib/sequel/plugins/subclasses.rb', line 39

def on_subclass
  @on_subclass
end

#subclassesObject (readonly)

All subclasses for the current model. Does not include the model itself.



43
44
45
# File 'lib/sequel/plugins/subclasses.rb', line 43

def subclasses
  @subclasses
end

Instance Method Details

#descendentsObject

All descendent classes of this model.



46
47
48
# File 'lib/sequel/plugins/subclasses.rb', line 46

def descendents
  Sequel.synchronize{subclasses.dup}.map{|x| [x] + x.send(:descendents)}.flatten
end

#inherited(subclass) ⇒ Object

Add the subclass to this model’s current subclasses, and initialize a new subclasses instance variable in the subclass.



55
56
57
58
59
# File 'lib/sequel/plugins/subclasses.rb', line 55

def inherited(subclass)
  super
  Sequel.synchronize{subclasses << subclass}
  on_subclass.call(subclass) if on_subclass
end