Class: Sunspot::Rails::Adapters::ActiveRecordDataAccessor
- Inherits:
-
Adapters::DataAccessor
- Object
- Adapters::DataAccessor
- Sunspot::Rails::Adapters::ActiveRecordDataAccessor
- Defined in:
- lib/sunspot/rails/adapters.rb
Instance Attribute Summary collapse
-
#include ⇒ Object
options for the find.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#select ⇒ Object
Returns the value of attribute select.
Instance Method Summary collapse
-
#initialize(clazz) ⇒ ActiveRecordDataAccessor
constructor
A new instance of ActiveRecordDataAccessor.
-
#load(id) ⇒ Object
Get one ActiveRecord instance out of the database by ID.
-
#load_all(ids) ⇒ Object
Get a collection of ActiveRecord instances out of the database by ID.
Constructor Details
#initialize(clazz) ⇒ ActiveRecordDataAccessor
Returns a new instance of ActiveRecordDataAccessor.
27 28 29 30 |
# File 'lib/sunspot/rails/adapters.rb', line 27 def initialize(clazz) super(clazz) @inherited_attributes = [:include, :select, :scopes] end |
Instance Attribute Details
#include ⇒ Object
options for the find
23 24 25 |
# File 'lib/sunspot/rails/adapters.rb', line 23 def include @include end |
#scopes ⇒ Object
Returns the value of attribute scopes.
24 25 26 |
# File 'lib/sunspot/rails/adapters.rb', line 24 def scopes @scopes end |
#select ⇒ Object
Returns the value of attribute select.
25 26 27 |
# File 'lib/sunspot/rails/adapters.rb', line 25 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
56 57 58 |
# File 'lib/sunspot/rails/adapters.rb', line 56 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
71 72 73 |
# File 'lib/sunspot/rails/adapters.rb', line 71 def load_all(ids) @clazz.where(@clazz.primary_key => ids).merge(scope_for_load) end |