null+****@clear*****
null+****@clear*****
2012年 6月 5日 (火) 15:07:15 JST
Haruka Yoshihara 2012-06-05 15:07:15 +0900 (Tue, 05 Jun 2012)
New Revision: a54cc6d6809e76726978b02108c1ea3f3dc9a4b0
Log:
Translater: Extract methods to translate arguments for commands
Modified files:
lib/groonga/tester.rb
Modified: lib/groonga/tester.rb (+30 -23)
===================================================================
--- lib/groonga/tester.rb 2012-06-05 14:26:00 +0900 (1036268)
+++ lib/groonga/tester.rb 2012-06-05 15:07:15 +0900 (db05820)
@@ -640,7 +640,6 @@ module Groonga
load_values = ""
end
else
- last_argument = ""
command = command.gsub(/,\s/, ",")
arguments = command.split(/(\s'.+?'\s|\s)/).collect(&:strip)
now_command = arguments.shift
@@ -650,27 +649,7 @@ module Groonga
load_values = ""
end
- arguments_count = 0
- last_command = ""
- arguments.each do |argument|
- next if argument.empty?
- if argument =~ /\A--/
- last_command = argument.sub(/\A--/, "")
- next
- end
-
- if last_command.empty?
- query_parameter =
- arguments_name(now_command)[arguments_count]
- else
- query_parameter = last_command
- end
-
- value = argument.gsub(/'/, "")
- translated_values << "#{query_parameter}=#{value}"
- arguments_count += 1
- last_command = ""
- end
+ translated_values = translate_arguments(now_command, arguments)
end
unless loading
@@ -679,13 +658,41 @@ module Groonga
translated_command << "?#{translated_values.join("&")}"
end
translated_commands << translated_command
- translated_values = []
end
end
translated_commands.join
end
private
+ def translate_arguments(now_command, arguments)
+ return [] if arguments.empty?
+ translated_values = []
+ last_argument = ""
+
+ arguments_count = 0
+ last_command = ""
+ arguments.each do |argument|
+ next if argument.empty?
+ if argument =~ /\A--/
+ last_command = argument.sub(/\A--/, "")
+ next
+ end
+
+ if last_command.empty?
+ query_parameter =
+ arguments_name(now_command)[arguments_count]
+ else
+ query_parameter = last_command
+ end
+
+ value = argument.gsub(/'/, "")
+ translated_values << "#{query_parameter}=#{value}"
+ arguments_count += 1
+ last_command = ""
+ end
+ translated_values
+ end
+
def arguments_name(command)
case command
when "table_create"