/usr/lib/ruby/vendor_ruby/sequel/plugins/subclasses.rb is in ruby-sequel 3.33.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | module Sequel
module Plugins
# 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 = Class.new(Sequel::Model)
# c.plugin :subclasses
# sc1 = Class.new(c)
# sc2 = Class.new(c)
# ssc1 = Class.new(sc1)
# c.subclasses # [sc1, sc2]
# sc1.subclasses # [ssc1]
# sc2.subclasses # []
# ssc1.subclasses # []
# c.descendents # [sc1, ssc1, sc2]
module Subclasses
# Initialize the subclasses instance variable for the model.
def self.apply(model)
model.instance_variable_set(:@subclasses, [])
end
module ClassMethods
# All subclasses for the current model. Does not
# include the model itself.
attr_reader :subclasses
# All descendent classes of this model.
def descendents
subclasses.map{|x| [x] + x.descendents}.flatten
end
# Add the subclass to this model's current subclasses,
# and initialize a new subclasses instance variable
# in the subclass.
def inherited(subclass)
super
subclasses << subclass
subclass.instance_variable_set(:@subclasses, [])
end
end
end
end
end
|