- A
- B
- C
- D
- I
- S
[RW] | abstract_class | Set this to true if this is an abstract class (see abstract_class?). |
Returns whether this class is an abstract class or not.
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.
True if this isn’t a concrete subclass needing a STI type condition.
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
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
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