forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.rb
36 lines (32 loc) · 1.04 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Elasticsearch
module Model
module Response
# Common funtionality for classes in the {Elasticsearch::Model::Response} module
#
module Base
attr_reader :klass, :response,
:total, :max_score
# @param klass [Class] The name of the model class
# @param response [Hash] The full response returned from Elasticsearch client
# @param results [Results] The collection of results
#
def initialize(klass, response, results=nil)
@klass = klass
@response = response
@total = response['hits']['total']
@max_score = response['hits']['max_score']
end
# @abstract Implement this method in specific class
#
def results
raise NotImplemented, "Implement this method in #{klass}"
end
# @abstract Implement this method in specific class
#
def records
raise NotImplemented, "Implement this method in #{klass}"
end
end
end
end
end