Sha256: 2a2fdbf88d6393cea62971c1a279d326eed2a7338610dea05b8b5e343be21b57

Contents?: true

Size: 1.07 KB

Versions: 36

Compression:

Stored size: 1.07 KB

Contents

module ActiveFedora
  module Inheritance
    extend ActiveSupport::Concern

    module ClassMethods
      # Returns the class descending directly from ActiveFedora::Base, or
      # an abstract class, if any, in the inheritance hierarchy.
      #
      # If A extends ActiveFedora::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.
      def base_class
        return File if self == File || superclass == File

        unless self <= Base
          raise ActiveFedoraError, "#{name} doesn't belong in a hierarchy descending from ActiveFedora"
        end

        if self == Base || superclass == Base || superclass.abstract_class?
          self
        else
          superclass.base_class
        end
      end

      # Abstract classes can't have default scopes.
      def abstract_class?
        self == Base
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
active-fedora-11.1.5 lib/active_fedora/inheritance.rb
active-fedora-11.1.4 lib/active_fedora/inheritance.rb
active-fedora-11.1.3 lib/active_fedora/inheritance.rb
active-fedora-11.1.2 lib/active_fedora/inheritance.rb
active-fedora-11.1.1 lib/active_fedora/inheritance.rb
active-fedora-11.1.0 lib/active_fedora/inheritance.rb
active-fedora-10.3.0 lib/active_fedora/inheritance.rb
active-fedora-11.0.1 lib/active_fedora/inheritance.rb
active-fedora-11.0.0 lib/active_fedora/inheritance.rb
active-fedora-10.3.0.rc2 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc7 lib/active_fedora/inheritance.rb
active-fedora-10.3.0.rc1 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc6 lib/active_fedora/inheritance.rb
active-fedora-10.2.1 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc5 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc4 lib/active_fedora/inheritance.rb
active-fedora-10.2.0 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc3 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc2 lib/active_fedora/inheritance.rb
active-fedora-11.0.0.rc1 lib/active_fedora/inheritance.rb