Sha256: 503866bce434f0f360a8de0cbe0399eafe4f1555901d9554999d1c61e621c417

Contents?: true

Size: 979 Bytes

Versions: 8

Compression:

Stored size: 979 Bytes

Contents

SOLR_DOCUMENT_ID = "id".freeze unless defined?(SOLR_DOCUMENT_ID)

module ActiveFedora
  # = ActiveFedora
  # This module mixes various methods into the including class,
  # much in the way ActiveRecord does.
  module Model
    # Takes a Fedora URI for a cModel, and returns a
    # corresponding Model if available
    # This method should reverse ClassMethods#to_class_uri
    # @return [Class, False] the class of the model or false, if it does not exist
    def self.from_class_uri(model_value)
      unless class_exists?(model_value)
        ActiveFedora::Base.logger.warn "'#{model_value}' is not a real class" if ActiveFedora::Base.logger
        return nil
      end
      ActiveFedora.class_from_string(model_value)
    end

    def self.class_exists?(class_name)
      return false if class_name.empty?
      klass = class_name.constantize
      return klass.is_a?(Class)
    rescue NameError
      return false
    end
    private_class_method :class_exists?
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/model.rb
active-fedora-9.7.2 lib/active_fedora/model.rb
active-fedora-9.9.1 lib/active_fedora/model.rb
active-fedora-9.9.0 lib/active_fedora/model.rb
active-fedora-9.8.2 lib/active_fedora/model.rb
active-fedora-9.8.1 lib/active_fedora/model.rb
active-fedora-9.8.0 lib/active_fedora/model.rb
active-fedora-9.7.1 lib/active_fedora/model.rb