[Groonga-commit] groonga/groonga-command at 84f33eb [fix-travis-ci-error] Add "to_hash" method

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Jan 13 17:30:23 JST 2016


YUKI Hiroshi	2013-09-12 19:06:49 +0900 (Thu, 12 Sep 2013)

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

  Message:
    Add "to_hash" method

  Modified files:
    lib/groonga/command/base.rb
    test/command/test-base.rb

  Modified: lib/groonga/command/base.rb (+10 -0)
===================================================================
--- lib/groonga/command/base.rb    2013-09-12 18:57:26 +0900 (6fc4e68)
+++ lib/groonga/command/base.rb    2013-09-12 19:06:49 +0900 (0fd3739)
@@ -117,6 +117,16 @@ module Groonga
         command_line.join(" ")
       end
 
+      def to_hash
+        converted_hash = {}
+        names = self.class.parameter_names.each do |parameter|
+          unless self[parameter].nil?
+            converted_hash[parameter] = self[parameter]
+          end
+        end
+        converted_hash
+      end
+
       private
       def construct_arguments(pair_arguments, ordered_arguments)
         arguments = {}

  Modified: test/command/test-base.rb (+25 -0)
===================================================================
--- test/command/test-base.rb    2013-09-12 18:57:26 +0900 (9d316c7)
+++ test/command/test-base.rb    2013-09-12 19:06:49 +0900 (1882aa7)
@@ -83,6 +83,31 @@ class BaseCommandTest < Test::Unit::TestCase
     end
   end
 
+  class CovnertToHashTest < self
+    class TemporaryCommand < Groonga::Command::Base
+      Groonga::Command.register("temporary_command", self)
+
+      class << self
+        def parameter_names
+          [
+            :parameter1,
+            :parameter2,
+            :parameter3,
+          ]
+        end
+      end
+    end
+
+    def test_convert
+      select = TemporaryCommand.new("temporary_command",
+                                    :parameter1 => "value1",
+                                    :parameter2 => "value2")
+      assert_equal({ :parameter1 => "value1",
+                     :parameter2 => "value2" },
+                   select.to_hash)
+    end
+  end
+
   sub_test_case("#[]") do
     def setup
       @table = "Users"
-------------- next part --------------
HTML����������������������������...
Télécharger 



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