lib/active_groonga/result_set.rb in activegroonga-1.0.3 vs lib/active_groonga/result_set.rb in activegroonga-1.0.4

- old
+ new

@@ -29,10 +29,11 @@ @n_records = options[:n_records] || @records.size compute_n_key_nested end def paginate(sort_keys, options={}) + options[:page] = normalize_page_value(options[:page]) records = @records.paginate(sort_keys, options) set = self.class.new(records, @klass, :expression => @expression) set.extend(PaginationProxy) set @@ -79,14 +80,30 @@ @n_key_nested += 1 domain = domain.domain end end + def normalize_page_value(page) + if page.blank? + 1 + else + begin + Integer(page) + rescue ArgumentError + 1 + end + end + end + module PaginationProxy Groonga::Pagination.instance_methods.each do |method_name| define_method(method_name) do @records.send(method_name) end end + + # For kaminari. + alias_method :num_pages, :n_pages + alias_method :limit_value, :page_size end end end