diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-10-26 15:51:02 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-10-26 15:51:02 +0100 |
commit | 9e4c41c903e8e58721f2c41776a8c60ddba7a0a9 (patch) | |
tree | d580824995d5ea4866b1d976818f3e3d03a02e53 /activerecord/lib/active_record/inheritance.rb | |
parent | a27b5178d9f1011545ecbf94008c5d890bab25d0 (diff) | |
download | rails-9e4c41c903e8e58721f2c41776a8c60ddba7a0a9.tar.gz rails-9e4c41c903e8e58721f2c41776a8c60ddba7a0a9.tar.bz2 rails-9e4c41c903e8e58721f2c41776a8c60ddba7a0a9.zip |
Remove ActiveRecord::Model
In the end I think the pain of implementing this seamlessly was not
worth the gain provided.
The intention was that it would allow plain ruby objects that might not
live in your main application to be subclassed and have persistence
mixed in. But I've decided that the benefit of doing that is not worth
the amount of complexity that the implementation introduced.
Diffstat (limited to 'activerecord/lib/active_record/inheritance.rb')
-rw-r--r-- | activerecord/lib/active_record/inheritance.rb | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 35273b0d81..a448fa1f5c 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -1,29 +1,22 @@ - module ActiveRecord - ActiveSupport.on_load(:active_record_config) do - # Determine whether to store the full constant name including namespace when using STI - mattr_accessor :store_full_sti_class, instance_accessor: false - self.store_full_sti_class = true - end - module Inheritance extend ActiveSupport::Concern included do - config_attribute :store_full_sti_class + # Determine whether to store the full constant name including namespace when using STI + class_attribute :store_full_sti_class, instance_writer: false + self.store_full_sti_class = true end module ClassMethods # True if this isn't a concrete subclass needing a STI type condition. def descends_from_active_record? - sup = active_record_super - - if sup.abstract_class? - sup.descends_from_active_record? - elsif self == Base + if self == Base false + elsif superclass.abstract_class? + superclass.descends_from_active_record? else - [Base, Model].include?(sup) || !columns_hash.include?(inheritance_column) + superclass == Base || !columns_hash.include?(inheritance_column) end end @@ -40,9 +33,8 @@ module ActiveRecord @symbolized_sti_name ||= sti_name.present? ? sti_name.to_sym : symbolized_base_class end - # Returns the class descending directly from ActiveRecord::Base (or - # that includes ActiveRecord::Model), or an abstract class, if any, in - # the inheritance hierarchy. + # Returns the class descending directly from ActiveRecord::Base, or + # an abstract class, if any, in the inheritance hierarchy. # # 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. @@ -50,15 +42,14 @@ module ActiveRecord # 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. def base_class - unless self < ActiveRecord::Tag + unless self < Base raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord" end - sup = active_record_super - if sup == Base || sup == Model || sup.abstract_class? + if superclass == Base || superclass.abstract_class? self else - sup.base_class + superclass.base_class end end @@ -97,14 +88,6 @@ module ActiveRecord sti_class.allocate.init_with('attributes' => record, 'column_types' => column_types) end - # For internal use. - # - # If this class includes ActiveRecord::Model then it won't have a - # superclass. So this provides a way to get to the 'root' (ActiveRecord::Model). - def active_record_super #:nodoc: - superclass < Model ? superclass : Model - end - protected # Returns the class type of the record using the current module as a prefix. So descendants of |