Sha256: 4088610dd94e71117802098fee0f74318f245096101fc90ca8faa6944244fc4d

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true
require 'active_model/conversion'

module Blacklight::Document
  module ActiveModelShim
    extend ActiveSupport::Concern

    include ::ActiveModel::Conversion

    module ClassMethods
      # This is actually an ActiveRecord method starting in Rails 5.2
      def polymorphic_name
        base_class.name
      end

      def primary_key
        unique_key
      end

      def base_class
        self
      end

      def repository
        Blacklight.default_index
      end

      def find id
        repository.find(id).documents.first
      end
    end
    
    ##
    # Unique ID for the document
    def id
      self[self.class.unique_key]
    end

    ##
    # accessors for reading attribute
    def [] *args
      _source.send :[], *args
    end
    
    def _read_attribute(attr)
      self[attr]
    end

    def as_json(options = nil)
      _source.as_json(options)
    end
    
    ##
    # ActiveRecord::Persistence method stubs to get non-AR objects to
    # play nice with e.g. Blacklight's bookmarks
    def persisted?
      true
    end

    def destroyed?
      false
    end
    
    def new_record?
      false
    end

    def marked_for_destruction?
      false
    end

    ##
    # #to_partial_path is also defined in Blacklight::Document, but
    # ActiveModel::Conversion (included above) will overwrite that..
    def to_partial_path
      'catalog/document'
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
blacklight-6.25.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.24.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.23.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.22.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.21.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.20.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.19.2 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.19.1 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.19.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.18.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.17.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.16.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-6.15.0 app/models/concerns/blacklight/document/active_model_shim.rb