Masafumi Yokoyama
null+****@clear*****
Thu Dec 8 16:11:21 JST 2016
Masafumi Yokoyama 2016-12-08 16:11:21 +0900 (Thu, 08 Dec 2016) New Revision: 6aef203739db7093f5e767e53d290001250b0352 https://github.com/groonga/groonga-command/commit/6aef203739db7093f5e767e53d290001250b0352 Message: select: support slices Modified files: lib/groonga/command/select.rb test/command/test-select.rb Modified: lib/groonga/command/select.rb (+30 -0) =================================================================== --- lib/groonga/command/select.rb 2016-12-06 16:07:01 +0900 (f7d5476) +++ lib/groonga/command/select.rb 2016-12-08 16:11:21 +0900 (1fe4f3d) @@ -1,4 +1,5 @@ # Copyright (C) 2012-2016 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2016 Masafumi Yokoyama <yokoyama �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -106,6 +107,13 @@ module Groonga @labeled_drilldowns ||= parse_labeled_drilldowns end + # @return [::Hash<String, Select>] The slices. + # + # @since 1.3.0 + def slices + @slices ||= parse_slices + end + def output_columns self[:output_columns] end @@ -157,6 +165,28 @@ module Groonga labeled_drilldowns end + def parse_slices + raw_slices = {} + @arguments.each do |name, value| + case name.to_s + when /\Aslices?\[(.+?)\]\.(.+?)\z/ + label = $1 + parameter_name = $2 + raw_slices[label] ||= {} + raw_slices[label][parameter_name] = value + end + end + build_slices(raw_slices) + end + + def build_slices(raw_slices) + slices = {} + raw_slices.each do |label, raw_slice| + slices[label] = Select.new(raw_slice) + end + slices + end + class Drilldown < Struct.new(:keys, :sort_keys, :output_columns, Modified: test/command/test-select.rb (+21 -0) =================================================================== --- test/command/test-select.rb 2016-12-06 16:07:01 +0900 (a2b7e86) +++ test/command/test-select.rb 2016-12-08 16:11:21 +0900 (1727e42) @@ -1,4 +1,5 @@ # Copyright (C) 2011-2016 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2016 Masafumi Yokoyama <yokoyama �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -216,4 +217,24 @@ class SelectCommandTest < Test::Unit::TestCase drilldown end end + + class SlicesTest < self + def test_multiple + parameters = { + "slices[groonga].query" => "tag:Groonga", + "slices[rroonga].filter" => "tag == Rroonga", + "slices[rroonga].sort_keys" => "date", + "slices[rroonga].output_columns" => "_key, date", + } + command = select_command(parameters) + + slices = { + "groonga" => select_command(:query => "tag:Groonga"), + "rroonga" => select_command(:filter => "tag == Rroonga", + :sort_keys => "date", + :output_columns => "_key, date"), + } + assert_equal(slices, command.slices) + end + end end -------------- next part -------------- HTML����������������������������...Download