Class: Rawscsi::SearchHelpers::ResultsActiveRecord
- Inherits:
-
Object
- Object
- Rawscsi::SearchHelpers::ResultsActiveRecord
- Defined in:
- lib/rawscsi/search_helpers/results_active_record.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(response, model) ⇒ ResultsActiveRecord
constructor
A new instance of ResultsActiveRecord.
Constructor Details
#initialize(response, model) ⇒ ResultsActiveRecord
Returns a new instance of ResultsActiveRecord.
6 7 8 9 |
# File 'lib/rawscsi/search_helpers/results_active_record.rb', line 6 def initialize(response, model) @response = response @model = model end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/rawscsi/search_helpers/results_active_record.rb', line 4 def response @response end |
Instance Method Details
#build ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rawscsi/search_helpers/results_active_record.rb', line 11 def build id_array = @response["hits"]["hit"].map {|h| model_id(h["id"]) } return [] if id_array.empty? results = if ActiveRecord::VERSION::MAJOR > 2 klass.where(:id => id_array).to_a else klass.find_all_by_id(id_array) end results.index_by(&:id).slice(*id_array).values end |