[Groonga-commit] groonga/groonga-command at 785a2bc [fix-travis-ci-error] Use Symbol for argument key

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 13 17:16:57 JST 2016


Kouhei Sutou	2012-11-25 17:45:38 +0900 (Sun, 25 Nov 2012)

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

  Message:
    Use Symbol for argument key

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

  Modified: lib/groonga/command/base.rb (+11 -3)
===================================================================
--- lib/groonga/command/base.rb    2012-11-25 17:38:31 +0900 (2fcbcea)
+++ lib/groonga/command/base.rb    2012-11-25 17:45:38 +0900 (b921f0d)
@@ -64,14 +64,14 @@ module Groonga
       def to_uri_format
         path = "/d/#{@name}"
         arguments =****@argum*****
-        output_type = arguments.delete("output_type")
+        output_type = arguments.delete(:output_type)
         path << ".#{output_type}" if output_type
         unless arguments.empty?
           sorted_arguments = arguments.sort_by do |name, _|
             name.to_s
           end
           uri_arguments = sorted_arguments.collect do |name, value|
-            "#{CGI.escape(name)}=#{CGI.escape(value)}"
+            "#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
           end
           path << "?"
           path << uri_arguments.join("&")
@@ -102,13 +102,21 @@ module Groonga
 
       private
       def construct_arguments(pair_arguments, ordered_arguments)
-        arguments = pair_arguments.dup
+        arguments = {}
+
+        pair_arguments.each do |key, value|
+          key = key.to_sym if key.is_a?(String)
+          arguments[key] = value
+        end
+
         names = self.class.parameter_names
         ordered_arguments.each_with_index do |argument, i|
           name = names[i]
           break if name.nil?
+          name = name.to_sym if name.is_a?(String)
           arguments[name] = argument
         end
+
         arguments
       end
     end

  Modified: lib/groonga/command/select.rb (+6 -6)
===================================================================
--- lib/groonga/command/select.rb    2012-11-25 17:38:31 +0900 (847cd3d)
+++ lib/groonga/command/select.rb    2012-11-25 17:45:38 +0900 (a87ff5e)
@@ -30,19 +30,19 @@ module Groonga
       end
 
       def sortby
-        @arguments["sortby"]
+        @arguments[:sortby]
       end
 
       def scorer
-        @arguments["scorer"]
+        @arguments[:scorer]
       end
 
       def query
-        @arguments["query"]
+        @arguments[:query]
       end
 
       def filter
-        @arguments["filter"]
+        @arguments[:filter]
       end
 
       def conditions
@@ -55,11 +55,11 @@ module Groonga
       end
 
       def drilldowns
-        @drilldowns ||= (@arguments["drilldown"] || "").split(/\s*,\s*/)
+        @drilldowns ||= (@arguments[:drilldown] || "").split(/\s*,\s*/)
       end
 
       def output_columns
-        @arguments["output_columns"]
+        @arguments[:output_columns]
       end
     end
   end

  Modified: test/test-table-create.rb (+5 -5)
===================================================================
--- test/test-table-create.rb    2012-11-25 17:38:31 +0900 (b729dec)
+++ test/test-table-create.rb    2012-11-25 17:45:38 +0900 (3001291)
@@ -30,11 +30,11 @@ class TableCreateTest < Test::Unit::TestCase
                       default_tokenizer)
       assert_instance_of(Groonga::Command::TableCreate, command)
       assert_equal({
-                     "name"              => name,
-                     "flags"             => flags,
-                     "key_type"          => key_type,
-                     "value_type"        => value_type,
-                     "default_tokenizer" => default_tokenizer,
+                     :name              => name,
+                     :flags             => flags,
+                     :key_type          => key_type,
+                     :value_type        => value_type,
+                     :default_tokenizer => default_tokenizer,
                    },
                    command.arguments)
     end
-------------- next part --------------
HTML����������������������������...
Download 



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