Class: Sunspot::Padrino::Adapters::ActiveRecordDataAccessor
- Inherits:
-
Adapters::DataAccessor
- Object
- Adapters::DataAccessor
- Sunspot::Padrino::Adapters::ActiveRecordDataAccessor
- Defined in:
- lib/sunspot/padrino/adapters.rb
Instance Attribute Summary collapse
-
#include ⇒ Object
options for the find.
-
#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.
26 27 28 29 |
# File 'lib/sunspot/padrino/adapters.rb', line 26 def initialize(clazz) super(clazz) @inherited_attributes = [:include, :select] end |
Instance Attribute Details
#include ⇒ Object
options for the find
23 24 25 |
# File 'lib/sunspot/padrino/adapters.rb', line 23 def include @include end |
#select ⇒ Object
Returns the value of attribute select.
24 25 26 |
# File 'lib/sunspot/padrino/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/sunspot/padrino/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/sunspot/padrino/adapters.rb', line 70 def load_all(ids) @clazz.where(@clazz.primary_key => ids).merge(scope_for_load) end |