Module: Spotlight::ArLight

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty, ActiveRecord::Associations, ActiveRecord::Inheritance, ActiveRecord::ModelSchema, ActiveRecord::Reflection
Defined in:
app/models/concerns/spotlight/ar_light.rb

Overview

Stub ActiveRecord methods to allow non-ActiveRecord::Base objects to participate in e.g. associations

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Returns true if comparison_object is the same exact object, or comparison_object is of the same type and self has an ID and it is equal to comparison_object.id.

Note that new records are different from any other record by definition, unless the other record is the receiver itself. Besides, if you fetch existing records with select and leave the ID out, you’re on your own, this predicate will return false.

Note also that destroying a record preserves its ID in the model instance, so deleted models are still comparable.



81
82
83
84
85
86
# File 'app/models/concerns/spotlight/ar_light.rb', line 81

def ==(other)
  super ||
    (other.instance_of?(self.class) &&
      id &&
      other.id == id)
end

#initialize(source_doc = {}, solr_response = nil) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



66
67
68
69
70
# File 'app/models/concerns/spotlight/ar_light.rb', line 66

def initialize(source_doc = {}, solr_response = nil)
  @association_cache = {}
  super
  yield self if block_given?
end