[Groonga-commit] ranguba/groonga-client at f6edf15 [master] Change Response::Select#slice return type

Back to archive index

Masafumi Yokoyama null+****@clear*****
Mon Dec 12 21:45:15 JST 2016


Masafumi Yokoyama	2016-12-12 21:45:15 +0900 (Mon, 12 Dec 2016)

  New Revision: f6edf151d9fda7dbf96c1a5c519ac564dacc4019
  https://github.com/ranguba/groonga-client/commit/f6edf151d9fda7dbf96c1a5c519ac564dacc4019

  Message:
    Change Response::Select#slice return type

  Modified files:
    lib/groonga/client/response/select.rb
    test/response/test-select-command-version1.rb
    test/response/test-select-command-version3.rb

  Modified: lib/groonga/client/response/select.rb (+6 -3)
===================================================================
--- lib/groonga/client/response/select.rb    2016-12-12 21:34:27 +0900 (a2e3e80)
+++ lib/groonga/client/response/select.rb    2016-12-12 21:45:15 +0900 (933bab9)
@@ -40,7 +40,7 @@ module Groonga
         #   Otherwise, `[drilldown1, drilldown2]` is returned.
         attr_accessor :drilldowns
 
-        # @return [::Hash<String, ::Array<::Hash<String, Object>>]
+        # @return [::Hash<String, Groonga::Client::Response::Select::Slice>]
         #
         # @since 0.3.4
         attr_accessor :slices
@@ -174,7 +174,7 @@ module Groonga
           slices = {}
           (raw_slices || {}).each do |key, slice_body|
             n_hits, body = parse_match_records_v1(slice_body)
-            slices[key] = body
+            slices[key] = Slice.new(key, n_hits, body)
           end
           slices
         end
@@ -183,7 +183,7 @@ module Groonga
           slices = {}
           (raw_slices || {}).each do |key, records|
             n_hits, body = parse_match_records_v3(records)
-            slices[key] = body
+            slices[key] = Slice.new(key, n_hits, body)
           end
           slices
         end
@@ -196,6 +196,9 @@ module Groonga
           # @deprecated since 0.2.6. Use {#records} instead.
           alias_method :items, :records
         end
+
+        class Slice < Struct.new(:key, :n_hits, :records)
+        end
       end
     end
   end

  Modified: test/response/test-select-command-version1.rb (+9 -1)
===================================================================
--- test/response/test-select-command-version1.rb    2016-12-12 21:34:27 +0900 (bc55e36)
+++ test/response/test-select-command-version1.rb    2016-12-12 21:45:15 +0900 (213070a)
@@ -367,13 +367,21 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
                          {"_id" => 3, "tag" => "groonga"},
                        ]
                      },
-                     slices(@body))
+                     collect_values(@body, &:records))
       end
 
       private
       def slices(body)
         create_response(body).slices
       end
+
+      def collect_values(body)
+        values = {}
+        slices(body).each do |label, slice|
+          values[label] = yield(slice)
+        end
+        values
+      end
     end
   end
 end

  Modified: test/response/test-select-command-version3.rb (+9 -1)
===================================================================
--- test/response/test-select-command-version3.rb    2016-12-12 21:34:27 +0900 (952cc5d)
+++ test/response/test-select-command-version3.rb    2016-12-12 21:45:15 +0900 (5bfb8ec)
@@ -332,13 +332,21 @@ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
                          {"_id" => 3, "tag" => "groonga"},
                        ]
                      },
-                     slices(@body))
+                     collect_values(@body, &:records))
       end
 
       private
       def slices(body)
         create_response(body).slices
       end
+
+      def collect_values(body)
+        values = {}
+        slices(body).each do |label, slice|
+          values[label] = yield(slice)
+        end
+        values
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index