Module: RSolr::Pagination::Client
- Defined in:
- lib/rsolr/pagination.rb
Overview
A mixin module for RSolr::Client – note, this must mixed-in via “extend” on a RSolr::Client instance.
Instance Method Summary collapse
-
#build_paginated_request(page, per_page, path, opts = nil) ⇒ Object
Just like RSolr::Client #build_request but converts the page and per_page arguments into :rows and :start.
-
#paginate(page, per_page, path, opts = nil) ⇒ Object
A paginated request method.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (protected)
Checks if the called method starts with “paginate_*” and converts the * to the solr request path. It then calls paginate with the appropriate arguments. If the called method doesn’t start with “paginate_”, the original/super RSolr::Client #method_missing method is called.
50 51 52 53 54 55 56 |
# File 'lib/rsolr/pagination.rb', line 50 def method_missing name, *args if name.to_s =~ /^paginated?_(.+)$/ paginate args[0], args[1], $1, *args[2..-1] else super name, *args end end |
Instance Method Details
#build_paginated_request(page, per_page, path, opts = nil) ⇒ Object
Just like RSolr::Client #build_request but converts the page and per_page arguments into :rows and :start.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rsolr/pagination.rb', line 27 def build_paginated_request page, per_page, path, opts = nil opts ||= {} opts[:page] = page opts[:per_page] = per_page opts[:params] ||= {} values = RSolr::Pagination.calculate_start_and_rows(page, per_page) opts[:params][:start] = values[0] opts[:params][:rows] = values[1] build_request path, opts end |
#paginate(page, per_page, path, opts = nil) ⇒ Object
A paginated request method.
19 20 21 22 |
# File 'lib/rsolr/pagination.rb', line 19 def paginate page, per_page, path, opts = nil request_context = build_paginated_request page, per_page, path, opts execute request_context end |