[Groonga-commit] groonga/groonga-command at e955319 [master] sort: support sort_hash_table option

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 31 14:04:05 JST 2017


Kouhei Sutou	2017-07-31 14:04:05 +0900 (Mon, 31 Jul 2017)

  New Revision: e955319170b248cd3ab932e9792bb34f8468f0ff
  https://github.com/groonga/groonga-command/commit/e955319170b248cd3ab932e9792bb34f8468f0ff

  Message:
    sort: support sort_hash_table option

  Modified files:
    lib/groonga/command/base.rb
    lib/groonga/command/dump.rb
    lib/groonga/command/load.rb
    lib/groonga/command/object-remove.rb
    test/command/test-dump.rb

  Modified: lib/groonga/command/base.rb (+11 -0)
===================================================================
--- lib/groonga/command/base.rb    2017-06-25 20:41:55 +0900 (c00a76a)
+++ lib/groonga/command/base.rb    2017-07-31 14:04:05 +0900 (a62edea)
@@ -216,6 +216,17 @@ module Groonga
         return nil if value.nil?
         value.strip.split(/\s*[| ]\s*/)
       end
+
+      def boolean_value(name, default_value)
+        parse_boolean_value(self[name], default_value)
+      end
+
+      def parse_boolean_value(value, default_value)
+        return default_value if value.nil?
+        value = value.strip
+        return default_value if value.empty?
+        value == "yes"
+      end
     end
   end
 end

  Modified: lib/groonga/command/dump.rb (+9 -3)
===================================================================
--- lib/groonga/command/dump.rb    2017-06-25 20:41:55 +0900 (8f8bf41)
+++ lib/groonga/command/dump.rb    2017-07-31 14:04:05 +0900 (bda9122)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2013-2016  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013-2017  Kouhei Sutou <kou �� 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
@@ -34,6 +32,7 @@ module Groonga
             :dump_records,
             :dump_indexes,
             :dump_configs,
+            :sort_hash_table,
           ]
         end
       end
@@ -43,6 +42,13 @@ module Groonga
       def output_type
         :none
       end
+
+      # @return [Boolean] `true` if `sort_hash_table` value is `"yes"`.
+      #
+      # @since 1.3.4
+      def sort_hash_table?
+        boolean_value(:sort_hash_table, false)
+      end
     end
   end
 end

  Modified: lib/groonga/command/load.rb (+1 -1)
===================================================================
--- lib/groonga/command/load.rb    2017-06-25 20:41:55 +0900 (abf5685)
+++ lib/groonga/command/load.rb    2017-07-31 14:04:05 +0900 (85fb1bf)
@@ -63,7 +63,7 @@ module Groonga
       #
       # @since 1.3.0
       def output_ids?
-        self[:output_ids] == "yes"
+        boolean_value(:output_ids, false)
       end
 
       private

  Modified: lib/groonga/command/object-remove.rb (+1 -1)
===================================================================
--- lib/groonga/command/object-remove.rb    2017-06-25 20:41:55 +0900 (42e70aa)
+++ lib/groonga/command/object-remove.rb    2017-07-31 14:04:05 +0900 (453b8d3)
@@ -48,7 +48,7 @@ module Groonga
       #
       # @since 1.1.7
       def force?
-        self[:force] == "yes"
+        boolean_value(:force, false)
       end
     end
   end

  Modified: test/command/test-dump.rb (+18 -3)
===================================================================
--- test/command/test-dump.rb    2017-06-25 20:41:55 +0900 (0fe30c4)
+++ test/command/test-dump.rb    2017-07-31 14:04:05 +0900 (8f50661)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2013-2016  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013-2017  Kouhei Sutou <kou �� 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
@@ -30,6 +28,7 @@ class DumpCommandTest < Test::Unit::TestCase
       dump_records = "no"
       dump_indexes = "yes"
       dump_configs = "no"
+      sort_hash_table = "yes"
 
       command = dump_command({},
                              [
@@ -39,6 +38,7 @@ class DumpCommandTest < Test::Unit::TestCase
                                dump_records,
                                dump_indexes,
                                dump_configs,
+                               sort_hash_table,
                              ])
       assert_equal({
                      :tables       => tables,
@@ -47,6 +47,7 @@ class DumpCommandTest < Test::Unit::TestCase
                      :dump_records => dump_records,
                      :dump_indexes => dump_indexes,
                      :dump_configs => dump_configs,
+                     :sort_hash_table => sort_hash_table,
                    },
                    command.arguments)
     end
@@ -57,4 +58,18 @@ class DumpCommandTest < Test::Unit::TestCase
       assert_equal(:none, dump_command.output_type)
     end
   end
+
+  class SortHashTableTest < self
+    def test_default
+      assert do
+        not dump_command.sort_hash_table?
+      end
+    end
+
+    def test_yes
+      assert do
+        dump_command("sort_hash_table" => "yes").sort_hash_table?
+      end
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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