Kouhei Sutou
null+****@clear*****
Thu Oct 2 21:08:36 JST 2014
Kouhei Sutou 2014-10-02 21:08:36 +0900 (Thu, 02 Oct 2014) New Revision: 8b4e04ad7ad92e6e4bd1caaa6947b0d8d9be2f8a https://github.com/groonga/groonga-command-parser/commit/8b4e04ad7ad92e6e4bd1caaa6947b0d8d9be2f8a Message: Support custom prefix URI format It requires groonga-command 1.0.9 or later. Modified files: groonga-command-parser.gemspec lib/groonga/command/parser.rb test/test-parser.rb Modified: groonga-command-parser.gemspec (+2 -2) =================================================================== --- groonga-command-parser.gemspec 2013-10-29 18:19:34 +0900 (e3dce52) +++ groonga-command-parser.gemspec 2014-10-02 21:08:36 +0900 (3d4e593) @@ -1,6 +1,6 @@ # -*- mode: ruby; coding: utf-8 -*- # -# Copyright (C) 2012-2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2012-2014 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 @@ -52,7 +52,7 @@ Gem::Specification.new do |spec| spec.licenses = ["LGPLv2.1+"] spec.require_paths = ["lib"] - spec.add_runtime_dependency("groonga-command") + spec.add_runtime_dependency("groonga-command", ">= 1.0.9") spec.add_runtime_dependency("yajl-ruby") spec.add_development_dependency("test-unit") Modified: lib/groonga/command/parser.rb (+12 -4) =================================================================== --- lib/groonga/command/parser.rb 2013-10-29 18:19:34 +0900 (530df80) +++ lib/groonga/command/parser.rb 2014-10-02 21:08:36 +0900 (08ee46f) @@ -16,6 +16,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require "English" require "shellwords" require "cgi" @@ -342,15 +343,15 @@ module Groonga end def parse_command(input) - if input.start_with?("/d/") + if input.start_with?("/") parse_uri_path(input) else parse_command_line(input) end end - def parse_uri_path(path) - name, arguments_string = path.split(/\?/, 2) + def parse_uri_path(relative_uri) + path, arguments_string = relative_uri.split(/\?/, 2) arguments = {} if arguments_string arguments_string.split(/&/).each do |argument_string| @@ -359,12 +360,19 @@ module Groonga arguments[key] = CGI.unescape(value) end end - name = name.gsub(/\A\/d\//, '') + if /\/([^\/]*)\z/=~ path + prefix = $PREMATCH + name = $1 + else + prefix = "" + name = path + end name, output_type = name.split(/\./, 2) arguments["output_type"] = output_type if output_type command_class = Command.find(name) command = command_class.new(name, arguments) command.original_format = :uri + command.path_prefix = prefix command end Modified: test/test-parser.rb (+13 -1) =================================================================== --- test/test-parser.rb 2013-10-29 18:19:34 +0900 (cf1567a) +++ test/test-parser.rb 2014-10-02 21:08:36 +0900 (d02b853) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2011-2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2011-2014 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 @@ -49,6 +49,18 @@ class ParserTest < Test::Unit::TestCase assert_equal({:table => "Users"}, command.arguments) end + def test_custom_prefix + path = "/db1/select?table=Users" + command = Groonga::Command::Parser.parse(path) + assert_equal("/db1", command.path_prefix) + end + + def test_deep_custom_prefix + path = "/groonga/db1/select?table=Users" + command = Groonga::Command::Parser.parse(path) + assert_equal("/groonga/db1", command.path_prefix) + end + class ParseTest < self include ParseTests end -------------- next part -------------- HTML����������������������������...Download