lib/gummi/db_layer/document/search/result.rb in gummi-0.3.2 vs lib/gummi/db_layer/document/search/result.rb in gummi-0.3.3
- old
+ new
@@ -5,24 +5,29 @@
class Result
attr_reader :took, :total, :hits, :facets
def initialize(response, converter, per_page, page)
+ @success = !!response
@response = Hashie::Mash.new response
- @took = @response.hits.took
- @total = @response.hits.total
- @hits = @response.hits.hits
- @facets = @response.facets
+ @took = @response.hits.took if @response.hits
+ @total = @response.hits.total if @response.hits
+ @hits = @response.hits.hits if @response.hits
+ @facets = @response.facets || Hashie::Mash.new
@converter = converter
@per_page = per_page
@page = page
end
def documents
@documents ||= begin
documents = Array(converter.hits_to_documents(hits)) if hits
Leaflet::Collection.new documents, total: total, page: page, per_page: per_page
end
+ end
+
+ def success?
+ @success
end
private
attr_reader :response, :converter, :per_page, :page, :hits