Sha256: 35701fddd28a043a1ca0472f3f39a309cebb441142d8e0616a97cc4f63997d72

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

require 'active_model/conversion'

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

    include ::ActiveModel::Conversion

    module ClassMethods
      def primary_key
        unique_key
      end

      def base_class
        self
      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

    ##
    # #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

15 entries across 15 versions & 1 rubygems

Version Path
blacklight-5.19.2 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.19.1 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.19.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.18.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.17.2 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.17.1 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.17.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.16.4 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.16.3 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.16.2 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.16.1 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.16.0 app/models/concerns/blacklight/document/active_model_shim.rb
blacklight-5.15.0 lib/blacklight/document/active_model_shim.rb
blacklight-5.14.0 lib/blacklight/document/active_model_shim.rb
blacklight-5.13.1 lib/blacklight/document/active_model_shim.rb