[Groonga-commit] groonga/groonga-command at 68580cb [master] Ignore nil value argument on formatting

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 30 19:08:09 JST 2014


Kouhei Sutou	2014-09-30 19:08:09 +0900 (Tue, 30 Sep 2014)

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

  Message:
    Ignore nil value argument on formatting

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

  Modified: lib/groonga/command/base.rb (+8 -2)
===================================================================
--- lib/groonga/command/base.rb    2014-09-30 19:03:34 +0900 (86a95eb)
+++ lib/groonga/command/base.rb    2014-09-30 19:08:09 +0900 (f48e183)
@@ -80,11 +80,11 @@ module Groonga
       end
 
       def to_uri_format
-        Format::URI.new(@name, @arguments).path
+        Format::URI.new(@name, normalized_arguments).path
       end
 
       def to_command_format
-        Format::Command.new(@name, @arguments).command_line
+        Format::Command.new(@name, normalized_arguments).command_line
       end
 
       private
@@ -111,6 +111,12 @@ module Groonga
         name = name.to_sym if name.is_a?(String)
         name
       end
+
+      def normalized_arguments
+        @arguments.reject do |_, value|
+          value.nil?
+        end
+      end
     end
   end
 end

  Modified: test/command/test-base.rb (+18 -0)
===================================================================
--- test/command/test-base.rb    2014-09-30 19:03:34 +0900 (de7d022)
+++ test/command/test-base.rb    2014-09-30 19:08:09 +0900 (9f0ae82)
@@ -48,6 +48,15 @@ class BaseCommandTest < Test::Unit::TestCase
                    "keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
                    select.to_uri_format)
     end
+
+    def test_nil
+      select = Groonga::Command::Base.new("select",
+                                          :table => "Users",
+                                          :filter => nil,
+                                          :output_type => "json")
+      assert_equal("/d/select.json?table=Users",
+                   select.to_uri_format)
+    end
   end
 
   class CovnertToCommandFormatTest < self
@@ -81,6 +90,15 @@ class BaseCommandTest < Test::Unit::TestCase
                      "--output_type \"json\" --table \"Users\"",
                    select.to_command_format)
     end
+
+    def test_nil
+      select = Groonga::Command::Base.new("select",
+                                          :table => "Users",
+                                          :filter => nil,
+                                          :output_type => "json")
+      assert_equal("select --output_type \"json\" --table \"Users\"",
+                   select.to_command_format)
+    end
   end
 
   sub_test_case("#[]") do
-------------- next part --------------
HTML����������������������������...
다운로드 



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