Kouhei Sutou
null+****@clear*****
Tue Jun 7 19:40:02 JST 2016
Kouhei Sutou 2016-06-07 19:40:02 +0900 (Tue, 07 Jun 2016) New Revision: 98627b957f732b2bb314324149eb61a1d8966103 https://github.com/ranguba/groonga-client-rails/commit/98627b957f732b2bb314324149eb61a1d8966103 Message: Add native Kaminari support Modified files: lib/groonga/client/searcher/select/request.rb test/apps/rails4-mongoid/Gemfile.lock test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb Modified: lib/groonga/client/searcher/select/request.rb (+21 -4) =================================================================== --- lib/groonga/client/searcher/select/request.rb 2016-03-28 12:56:54 +0900 (8440b1a) +++ lib/groonga/client/searcher/select/request.rb 2016-06-07 19:40:02 +0900 (c78022c) @@ -34,7 +34,7 @@ module Groonga end def result_set - @result_set ||= ResultSet.new(response) + @result_set ||= create_result_set end def match_columns(value) @@ -74,15 +74,32 @@ module Groonga def paginate(page, per_page: 10) page ||= 1 page = page.to_i - return self if page < 0 - - offset(per_page * page).limit(per_page) + if page <= 0 + offset = 0 + else + offset = per_page * (page - 1) + end + offset(offset).limit(per_page) end private def create_request(parameters) self.class.new(parameters) end + + def create_result_set + result_set = ResultSet.new(response) + if paginated? and defined?(Kaminari) + result_set.extend(Kaminari::ConfigurationMethods::ClassMethods) + result_set.extend(Kaminari::PageScopeMethods) + end + result_set + end + + def paginated? + parameters = to_parameters + parameters.key?(:offset) and parameters.key?(:limit) + end end # @private Modified: test/apps/rails4-mongoid/Gemfile.lock (+4 -4) =================================================================== --- test/apps/rails4-mongoid/Gemfile.lock 2016-03-28 12:56:54 +0900 (552e4ca) +++ test/apps/rails4-mongoid/Gemfile.lock 2016-06-07 19:40:02 +0900 (b93a328) @@ -1,7 +1,7 @@ PATH remote: ../../../ specs: - groonga-client-rails (0.9.0) + groonga-client-rails (0.9.3) groonga-client (>= 0.2.4) rails @@ -68,13 +68,13 @@ GEM globalid (0.3.6) activesupport (>= 4.1.0) gqtp (1.0.6) - groonga-client (0.2.4) + groonga-client (0.2.5) gqtp (>= 1.0.4) groonga-command (>= 1.2.0) hashie groonga-command (1.2.0) json - hashie (3.4.3) + hashie (3.4.4) i18n (0.7.0) jbuilder (2.4.1) activesupport (>= 3.0.0, < 5.1) @@ -187,4 +187,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.11.2 + 1.12.5 Modified: test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb (+5 -5) =================================================================== --- test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb 2016-03-28 12:56:54 +0900 (503836e) +++ test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb 2016-06-07 19:40:02 +0900 (6b181fe) @@ -108,11 +108,11 @@ class PostsSearcherTest < ActionController::TestCase record["body"] end assert_equal([ - "Hello 15", - "Hello 16", - "Hello 17", - "Hello 18", - "Hello 19", + "Hello 10", + "Hello 11", + "Hello 12", + "Hello 13", + "Hello 14", ], data) end -------------- next part -------------- HTML����������������������������... Descargar