Methods
A
B
C
D
I
S
Attributes
[RW] abstract_class

Set this to true if this is an abstract class (see abstract_class?).

Instance Public methods
abstract_class?()

Returns whether this class is an abstract class or not.

    # File activerecord/lib/active_record/inheritance.rb, line 50
50:       def abstract_class?
51:         defined?(@abstract_class) && @abstract_class == true
52:       end
base_class()

Returns the base AR subclass that this class descends from. If A extends AR::Base, A.base_class will return A. If B descends from A through some arbitrarily deep hierarchy, B.base_class will return A.

If B < A and C < B and if A is an abstract_class then both B.base_class and C.base_class would return B as the answer since A is an abstract_class.

    # File activerecord/lib/active_record/inheritance.rb, line 42
42:       def base_class
43:         class_of_active_record_descendant(self)
44:       end
descends_from_active_record?()

True if this isn’t a concrete subclass needing a STI type condition.

    # File activerecord/lib/active_record/inheritance.rb, line 15
15:       def descends_from_active_record?
16:         if superclass.abstract_class?
17:           superclass.descends_from_active_record?
18:         else
19:           superclass == Base || !columns_hash.include?(inheritance_column)
20:         end
21:       end
instantiate(record)

Finder methods must instantiate through this method to work with the single-table inheritance model that makes it possible to create objects of different types from the same table.

    # File activerecord/lib/active_record/inheritance.rb, line 61
61:       def instantiate(record)
62:         sti_class = find_sti_class(record[inheritance_column])
63:         record_id = sti_class.primary_key && record[sti_class.primary_key]
64: 
65:         if ActiveRecord::IdentityMap.enabled? && record_id
66:           instance = use_identity_map(sti_class, record_id, record)
67:         else
68:           instance = sti_class.allocate.init_with('attributes' => record)
69:         end
70: 
71:         instance
72:       end
sti_name()
    # File activerecord/lib/active_record/inheritance.rb, line 54
54:       def sti_name
55:         store_full_sti_class ? name : name.demodulize
56:       end
symbolized_base_class()
    # File activerecord/lib/active_record/inheritance.rb, line 28
28:       def symbolized_base_class
29:         @symbolized_base_class ||= base_class.to_s.to_sym
30:       end
symbolized_sti_name()
    # File activerecord/lib/active_record/inheritance.rb, line 32
32:       def symbolized_sti_name
33:         @symbolized_sti_name ||= sti_name.present? ? sti_name.to_sym : symbolized_base_class
34:       end
Instance Protected methods
class_of_active_record_descendant(klass)

Returns the class descending directly from ActiveRecord::Base or an abstract class, if any, in the inheritance hierarchy.

    # File activerecord/lib/active_record/inheritance.rb, line 78
78:       def class_of_active_record_descendant(klass)
79:         if klass == Base || klass.superclass == Base || klass.superclass.abstract_class?
80:           klass
81:         elsif klass.superclass.nil?
82:           raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord"
83:         else
84:           class_of_active_record_descendant(klass.superclass)
85:         end
86:       end
compute_type(type_name)

Returns the class type of the record using the current module as a prefix. So descendants of MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.

     # File activerecord/lib/active_record/inheritance.rb, line 90
 90:       def compute_type(type_name)
 91:         if type_name.match(/^::/)
 92:           # If the type is prefixed with a scope operator then we assume that
 93:           # the type_name is an absolute reference.
 94:           ActiveSupport::Dependencies.constantize(type_name)
 95:         else
 96:           # Build a list of candidates to search for
 97:           candidates = []
 98:           name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
 99:           candidates << type_name
100: 
101:           candidates.each do |candidate|
102:             begin
103:               constant = ActiveSupport::Dependencies.constantize(candidate)
104:               return constant if candidate == constant.to_s
105:             rescue NameError => e
106:               # We don't want to swallow NoMethodError < NameError errors
107:               raise e unless e.instance_of?(NameError)
108:             end
109:           end
110: 
111:           raise NameError, "uninitialized constant #{candidates.first}"
112:         end
113:       end