Sha256: 6e672447866e9e02e79f1858e37bde9447fbaca149f54dcc05594c04689545c5

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

module ActiveFedora
  class SolrHit < Delegator
    def self.for(hit)
      return hit if hit.is_a? ActiveFedora::SolrHit

      SolrHit.new(hit)
    end

    delegate :models, to: :classifier

    def __getobj__
      @document # return object we are delegating to, required
    end

    alias static_config __getobj__

    def __setobj__(obj)
      @document = obj
    end

    attr_reader :document

    def initialize(document)
      document = document.with_indifferent_access
      super
      @document = document
    end

    def id
      document[ActiveFedora.id_field]
    end

    def rdf_uri
      ::RDF::URI.new(ActiveFedora::Base.id_to_uri(id))
    end

    def model(opts = {})
      best_model_match = classifier.best_model(opts)
      ActiveFedora::Base.logger.warn "Could not find a model for #{id}, defaulting to ActiveFedora::Base" if ActiveFedora::Base.logger && best_model_match == ActiveFedora::Base
      best_model_match
    end

    def model?(model_to_check)
      models.any? do |model|
        model_to_check >= model
      end
    end

    def reify(opts = {})
      model(opts).find(id, cast: true)
    end

    private

      def classifier
        ActiveFedora.model_mapper.classifier(document)
      end

      def profile_json
        Array(document[ActiveFedora::IndexingService.profile_solr_name]).first
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active-fedora-11.0.0.rc7 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc6 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc5 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc4 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc3 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc2 lib/active_fedora/solr_hit.rb
active-fedora-11.0.0.rc1 lib/active_fedora/solr_hit.rb