groonga-command 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +21 -0
- data/README.md +47 -0
- data/Rakefile +44 -0
- data/doc/text/lgpl-2.1.txt +502 -0
- data/doc/text/news.md +5 -0
- data/groonga-command.gemspec +64 -0
- data/lib/groonga/command.rb +20 -0
- data/lib/groonga/command/base.rb +138 -0
- data/lib/groonga/command/column-create.rb +39 -0
- data/lib/groonga/command/column-remove.rb +36 -0
- data/lib/groonga/command/column-rename.rb +37 -0
- data/lib/groonga/command/delete.rb +38 -0
- data/lib/groonga/command/error.rb +24 -0
- data/lib/groonga/command/get.rb +39 -0
- data/lib/groonga/command/load.rb +56 -0
- data/lib/groonga/command/parser.rb +424 -0
- data/lib/groonga/command/select.rb +69 -0
- data/lib/groonga/command/suggest.rb +47 -0
- data/lib/groonga/command/table-create.rb +39 -0
- data/lib/groonga/command/table-remove.rb +35 -0
- data/lib/groonga/command/table-rename.rb +36 -0
- data/lib/groonga/command/truncate.rb +35 -0
- data/lib/groonga/command/version.rb +23 -0
- data/test/command/test-base.rb +114 -0
- data/test/command/test-column-create.rb +47 -0
- data/test/command/test-column-remove.rb +41 -0
- data/test/command/test-column-rename.rb +43 -0
- data/test/command/test-delete.rb +45 -0
- data/test/command/test-get.rb +44 -0
- data/test/command/test-load.rb +49 -0
- data/test/command/test-select.rb +60 -0
- data/test/command/test-suggest.rb +68 -0
- data/test/command/test-table-create.rb +48 -0
- data/test/command/test-table-remove.rb +39 -0
- data/test/command/test-table-rename.rb +41 -0
- data/test/command/test-truncate.rb +39 -0
- data/test/groonga-command-test-utils.rb +102 -0
- data/test/run-test.rb +39 -0
- data/test/test-parser.rb +353 -0
- metadata +237 -0
data/doc/text/news.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
base_dir = File.dirname(__FILE__)
|
20
|
+
lib_dir = File.join(base_dir, "lib")
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(lib_dir)
|
23
|
+
require "groonga/command/version"
|
24
|
+
|
25
|
+
clean_white_space = lambda do |entry|
|
26
|
+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
Gem::Specification.new do |spec|
|
30
|
+
spec.name = "groonga-command"
|
31
|
+
spec.version = Groonga::Command::VERSION.dup
|
32
|
+
|
33
|
+
spec.authors = ["Kouhei Sutou"]
|
34
|
+
spec.email = ["kou@clear-code.com"]
|
35
|
+
|
36
|
+
readme = File.read("README.md")
|
37
|
+
readme.force_encoding("UTF-8") if readme.respond_to?(:force_encoding)
|
38
|
+
entries = readme.split(/^\#\#\s(.*)$/)
|
39
|
+
description = clean_white_space.call(entries[entries.index("Description") + 1])
|
40
|
+
spec.summary, spec.description, = description.split(/\n\n+/, 3)
|
41
|
+
|
42
|
+
spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
|
43
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
44
|
+
spec.files += Dir.glob("doc/text/*")
|
45
|
+
spec.test_files += Dir.glob("test/**/*")
|
46
|
+
# Dir.chdir("bin") do
|
47
|
+
# spec.executables = Dir.glob("*")
|
48
|
+
# end
|
49
|
+
|
50
|
+
spec.homepage = "https://github.com/groonga/groonga-command"
|
51
|
+
spec.licenses = ["LGPLv2.1+"]
|
52
|
+
spec.require_paths = ["lib"]
|
53
|
+
|
54
|
+
spec.add_runtime_dependency("yajl-ruby")
|
55
|
+
|
56
|
+
spec.add_development_dependency("test-unit")
|
57
|
+
spec.add_development_dependency("test-unit-notify")
|
58
|
+
spec.add_development_dependency("rake")
|
59
|
+
spec.add_development_dependency("bundler")
|
60
|
+
spec.add_development_dependency("packnga")
|
61
|
+
spec.add_development_dependency("yard")
|
62
|
+
spec.add_development_dependency("redcarpet")
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/version"
|
20
|
+
require "groonga/command/parser"
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "English"
|
20
|
+
require "cgi"
|
21
|
+
|
22
|
+
module Groonga
|
23
|
+
module Command
|
24
|
+
class << self
|
25
|
+
@@registered_commands = {}
|
26
|
+
def register(name, klass)
|
27
|
+
@@registered_commands[name] = klass
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(name)
|
31
|
+
@@registered_commands[name] || Base
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Base
|
36
|
+
class << self
|
37
|
+
def parameter_names
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :name, :arguments
|
43
|
+
attr_accessor :original_format, :original_source
|
44
|
+
def initialize(name, pair_arguments, ordered_arguments=[])
|
45
|
+
@name = name
|
46
|
+
@arguments = construct_arguments(pair_arguments, ordered_arguments)
|
47
|
+
@original_format = nil
|
48
|
+
@original_source = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def [](name)
|
52
|
+
@arguments[normalize_name(name)]
|
53
|
+
end
|
54
|
+
|
55
|
+
def has_key?(name)
|
56
|
+
@arguments.has_key?(normalize_name(name))
|
57
|
+
end
|
58
|
+
|
59
|
+
def ==(other)
|
60
|
+
other.is_a?(self.class) and
|
61
|
+
@name == other.name and
|
62
|
+
@arguments == other.arguments
|
63
|
+
end
|
64
|
+
|
65
|
+
def uri_format?
|
66
|
+
@original_format == :uri
|
67
|
+
end
|
68
|
+
|
69
|
+
def command_format?
|
70
|
+
@original_format == :command
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_uri_format
|
74
|
+
path = "/d/#{@name}"
|
75
|
+
arguments = @arguments.dup
|
76
|
+
output_type = arguments.delete(:output_type)
|
77
|
+
path << ".#{output_type}" if output_type
|
78
|
+
unless arguments.empty?
|
79
|
+
sorted_arguments = arguments.sort_by do |name, _|
|
80
|
+
name.to_s
|
81
|
+
end
|
82
|
+
uri_arguments = sorted_arguments.collect do |name, value|
|
83
|
+
"#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
|
84
|
+
end
|
85
|
+
path << "?"
|
86
|
+
path << uri_arguments.join("&")
|
87
|
+
end
|
88
|
+
path
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_command_format
|
92
|
+
command_line = [@name]
|
93
|
+
sorted_arguments = @arguments.sort_by do |name, _|
|
94
|
+
name.to_s
|
95
|
+
end
|
96
|
+
sorted_arguments.each do |name, value|
|
97
|
+
escaped_value = value.gsub(/[\n"\\]/) do
|
98
|
+
special_character = $MATCH
|
99
|
+
case special_character
|
100
|
+
when "\n"
|
101
|
+
"\\n"
|
102
|
+
else
|
103
|
+
"\\#{special_character}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
command_line << "--#{name}"
|
107
|
+
command_line << "\"#{escaped_value}\""
|
108
|
+
end
|
109
|
+
command_line.join(" ")
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
def construct_arguments(pair_arguments, ordered_arguments)
|
114
|
+
arguments = {}
|
115
|
+
|
116
|
+
pair_arguments.each do |key, value|
|
117
|
+
key = key.to_sym if key.is_a?(String)
|
118
|
+
arguments[key] = value
|
119
|
+
end
|
120
|
+
|
121
|
+
names = self.class.parameter_names
|
122
|
+
ordered_arguments.each_with_index do |argument, i|
|
123
|
+
name = names[i]
|
124
|
+
break if name.nil?
|
125
|
+
name = name.to_sym if name.is_a?(String)
|
126
|
+
arguments[name] = argument
|
127
|
+
end
|
128
|
+
|
129
|
+
arguments
|
130
|
+
end
|
131
|
+
|
132
|
+
def normalize_name(name)
|
133
|
+
name = name.to_sym if name.is_a?(String)
|
134
|
+
name
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class ColumnCreate < Base
|
24
|
+
Command.register("column_create", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
:name,
|
31
|
+
:flags,
|
32
|
+
:type,
|
33
|
+
:source,
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class ColumnRemove < Base
|
24
|
+
Command.register("column_remove", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
:name,
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class ColumnRename < Base
|
24
|
+
Command.register("column_rename", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
:name,
|
31
|
+
:new_name,
|
32
|
+
]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class Delete < Base
|
24
|
+
Command.register("delete", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
:key,
|
31
|
+
:id,
|
32
|
+
:filter,
|
33
|
+
]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
module Groonga
|
20
|
+
module Command
|
21
|
+
class Error < StandardError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class Get < Base
|
24
|
+
Command.register("get", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
:key,
|
31
|
+
:output_columns,
|
32
|
+
:id
|
33
|
+
]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|