Module: Sequel::Plugins::Subclasses::ClassMethods
- Defined in:
- lib/sequel/plugins/subclasses.rb
Instance Attribute Summary collapse
-
#on_subclass ⇒ Object
readonly
Callable object that should be called with every descendent class created.
-
#subclasses ⇒ Object
readonly
All subclasses for the current model.
Instance Method Summary collapse
-
#descendents ⇒ Object
All descendent classes of this model.
-
#inherited(subclass) ⇒ Object
Add the subclass to this model’s current subclasses, and initialize a new subclasses instance variable in the subclass.
Instance Attribute Details
#on_subclass ⇒ Object (readonly)
Callable object that should be called with every descendent class created.
37 38 39 |
# File 'lib/sequel/plugins/subclasses.rb', line 37 def on_subclass @on_subclass end |
#subclasses ⇒ Object (readonly)
All subclasses for the current model. Does not include the model itself.
41 42 43 |
# File 'lib/sequel/plugins/subclasses.rb', line 41 def subclasses @subclasses end |
Instance Method Details
#descendents ⇒ Object
All descendent classes of this model.
44 45 46 |
# File 'lib/sequel/plugins/subclasses.rb', line 44 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.
53 54 55 56 57 |
# File 'lib/sequel/plugins/subclasses.rb', line 53 def inherited(subclass) super Sequel.synchronize{subclasses << subclass} on_subclass.call(subclass) if on_subclass end |