Class: Sunspot::Rails::Adapters::ActiveRecordDataAccessor

Inherits:
Adapters::DataAccessor
  • Object
show all
Defined in:
lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz) ⇒ ActiveRecordDataAccessor

Returns a new instance of ActiveRecordDataAccessor.



26
27
28
29
# File 'lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb', line 26

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

Instance Attribute Details

#includeObject

options for the find



23
24
25
# File 'lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb', line 23

def include
  @include
end

#selectObject

Returns the value of attribute select.



24
25
26
# File 'lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb', line 24

def select
  @select
end

Instance Method Details

#load(id) ⇒ Object

Get one ActiveRecord instance out of the database by ID

Parameters

id<String>

Database ID of model to retreive

Returns

ActiveRecord::Base

ActiveRecord model



55
56
57
# File 'lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb', line 55

def load(id)
  @clazz.where(@clazz.primary_key => id).merge(scope_for_load).first
end

#load_all(ids) ⇒ Object

Get a collection of ActiveRecord instances out of the database by ID

Parameters

ids<Array>

Database IDs of models to retrieve

Returns

Array

Collection of ActiveRecord models



70
71
72
# File 'lib/active_record_sunspotter/sunspot_rails_2.1.0_sunspot_rails_adapters.rb', line 70

def load_all(ids)
  @clazz.where(@clazz.primary_key => ids).merge(scope_for_load)
end