Module: Pagy::ElasticsearchRailsExtra::Pagy

Included in:
Pagy
Defined in:
lib/pagy/extras/elasticsearch_rails.rb

Overview

Additions for the Pagy class

Instance Method Summary collapse

Instance Method Details

#new_from_elasticsearch_rails(response, vars = {}) ⇒ Object

Create a Pagy object from an Elasticsearch::Model::Response::Response object



35
36
37
38
39
40
# File 'lib/pagy/extras/elasticsearch_rails.rb', line 35

def new_from_elasticsearch_rails(response, vars = {})
  vars[:items] = response.search.options[:size] || 10
  vars[:page]  = ((response.search.options[:from] || 0) / vars[:items]) + 1
  vars[:count] = ElasticsearchRailsExtra.total_count(response)
  new(vars)
end