Class: Sunspot::Mongo::DataAccessor

Inherits:
Adapters::DataAccessor
  • Object
show all
Defined in:
lib/sunspot/mongo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz) ⇒ DataAccessor

inspired by how Sunspot does this for ActiveRecord



24
25
26
27
# File 'lib/sunspot/mongo.rb', line 24

def initialize(clazz)
  super(clazz)
  @inherited_attributes = [:include]
end

Instance Attribute Details

#includeObject

Returns the value of attribute include.



21
22
23
# File 'lib/sunspot/mongo.rb', line 21

def include
  @include
end

Instance Method Details

#load(id) ⇒ Object



29
30
31
# File 'lib/sunspot/mongo.rb', line 29

def load(id)
  scope.find(id)
end

#load_all(ids) ⇒ Object



33
34
35
# File 'lib/sunspot/mongo.rb', line 33

def load_all(ids)
  scope.find(ids)
end

#scopeObject



37
38
39
40
# File 'lib/sunspot/mongo.rb', line 37

def scope
  sc = @clazz.respond_to?(:criteria) ? @clazz.criteria : @clazz
  @include ? sc.includes(@include) : sc
end