Sha256: 057896b4ed5e48a7cf35c1f072e6d31b2c3d786855d704b9f781ace55f57fd87

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

module ActiveFedora
  class FedoraSolrMismatchError < ActiveFedora::ObjectNotFoundError
    def initialize(fedora_id, solr_document_id)
      super("Solr ID and Fedora ID do not match; Solr ID=#{solr_document_id}, Fedora ID=#{fedora_id}")
    end
  end

  # Responsible for loading an ActiveFedora::Base proxy from a Solr document.
  class SolrInstanceLoader
    attr_reader :context, :id
    private :context, :id
    def initialize(context, id, solr_doc = nil)
      @context = context
      @id = id
      self.solr_doc = solr_doc
    end

    def object
      return @object if @object
      @object = solr_doc.instantiate_with_json
      @object.readonly!
      @object.freeze
      @object
    end

    private

      def solr_doc
        @solr_doc ||= begin
          self.solr_doc = context.search_by_id(id)
        end
      end

      def solr_doc=(solr_doc)
        unless solr_doc.nil?
          solr_doc = ActiveFedora::SolrHit.for(solr_doc)
          validate_solr_doc_and_id!(solr_doc)
          @solr_doc = solr_doc
        end
      end

      def validate_solr_doc_and_id!(document)
        return if id == document.id
        raise ActiveFedora::FedoraSolrMismatchError, id, document.id
      end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active-fedora-10.3.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.3.0.rc2 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.3.0.rc1 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.2.1 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.2.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.1.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.1.0.rc1 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.0.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.0.0.beta4 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.0.0.beta3 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.0.0.beta2 lib/active_fedora/solr_instance_loader.rb
active-fedora-10.0.0.beta1 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.13.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.12.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.11.0 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.10.4 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.10.3 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.10.2 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.10.1 lib/active_fedora/solr_instance_loader.rb
active-fedora-9.10.0 lib/active_fedora/solr_instance_loader.rb