groonga-command 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -32,7 +32,8 @@ end
32
32
  helper.install
33
33
  spec = helper.gemspec
34
34
 
35
- Packnga::DocumentTask.new(spec) do
35
+ Packnga::DocumentTask.new(spec) do |task|
36
+ task.translate_languages = ["ja"]
36
37
  end
37
38
 
38
39
  Packnga::ReleaseTask.new(spec) do
data/doc/text/news.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # News
2
2
 
3
+ ## 1.0.4: 2013-09-18
4
+
5
+ ### Improvements
6
+
7
+ * {Groonga::Command::TableCreate}: Supported "--normalizer" parameter.
8
+ * {Groonga::Command::Select}: Supported all parameters.
9
+
10
+ ### Fixes
11
+
12
+ * Fixed a bug that is caused by using with rroonga.
13
+
3
14
  ## 1.0.3: 2013-07-23
4
15
 
5
16
  ### Improvements
@@ -16,8 +16,8 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
- require "English"
20
- require "cgi"
19
+ require "groonga/command/format/uri"
20
+ require "groonga/command/format/command"
21
21
 
22
22
  module Groonga
23
23
  module Command
@@ -79,42 +79,11 @@ module Groonga
79
79
  end
80
80
 
81
81
  def to_uri_format
82
- path = "/d/#{@name}"
83
- arguments = @arguments.dup
84
- output_type = arguments.delete(:output_type)
85
- path << ".#{output_type}" if output_type
86
- unless arguments.empty?
87
- sorted_arguments = arguments.sort_by do |name, _|
88
- name.to_s
89
- end
90
- uri_arguments = sorted_arguments.collect do |name, value|
91
- "#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
92
- end
93
- path << "?"
94
- path << uri_arguments.join("&")
95
- end
96
- path
82
+ Format::URI.new(@name, @arguments).path
97
83
  end
98
84
 
99
85
  def to_command_format
100
- command_line = [@name]
101
- sorted_arguments = @arguments.sort_by do |name, _|
102
- name.to_s
103
- end
104
- sorted_arguments.each do |name, value|
105
- escaped_value = value.gsub(/[\n"\\]/) do
106
- special_character = $MATCH
107
- case special_character
108
- when "\n"
109
- "\\n"
110
- else
111
- "\\#{special_character}"
112
- end
113
- end
114
- command_line << "--#{name}"
115
- command_line << "\"#{escaped_value}\""
116
- end
117
- command_line.join(" ")
86
+ Format::Command.new(@name, @arguments).command_line
118
87
  end
119
88
 
120
89
  private
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 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
+
21
+ module Groonga
22
+ module Command
23
+ module Format
24
+ class Command
25
+ class << self
26
+ def escape_value(value)
27
+ escaped_value = value.gsub(/[\n"\\]/) do
28
+ special_character = $MATCH
29
+ case special_character
30
+ when "\n"
31
+ "\\n"
32
+ else
33
+ "\\#{special_character}"
34
+ end
35
+ end
36
+ "\"#{escaped_value}\""
37
+ end
38
+ end
39
+
40
+ def initialize(name, arguments)
41
+ @name = name
42
+ @arguments = arguments
43
+ end
44
+
45
+ def command_line
46
+ components = [@name]
47
+ sorted_arguments = @arguments.sort_by do |name, _|
48
+ name.to_s
49
+ end
50
+ sorted_arguments.each do |name, value|
51
+ components << "--#{name}"
52
+ components << self.class.escape_value(value)
53
+ end
54
+ components.join(" ")
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012-2013 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 "cgi"
20
+
21
+ module Groonga
22
+ module Command
23
+ module Format
24
+ class URI
25
+ def initialize(name, arguments)
26
+ @name = name
27
+ @arguments = arguments
28
+ end
29
+
30
+ def path
31
+ path = "/d/#{@name}"
32
+ arguments = @arguments.dup
33
+ output_type = arguments.delete(:output_type)
34
+ path << ".#{output_type}" if output_type
35
+ unless arguments.empty?
36
+ sorted_arguments = arguments.sort_by do |name, _|
37
+ name.to_s
38
+ end
39
+ uri_arguments = sorted_arguments.collect do |name, value|
40
+ "#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
41
+ end
42
+ path << "?"
43
+ path << uri_arguments.join("&")
44
+ end
45
+ path
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -305,7 +305,7 @@ module Groonga
305
305
  @buffer = rest
306
306
  @json_parser = Yajl::Parser.new
307
307
  @json_parser.on_parse_complete = lambda do |object|
308
- if object.is_a?(Array) and @command.columns.nil?
308
+ if object.is_a?(::Array) and @command.columns.nil?
309
309
  @command.columns = object
310
310
  on_load_columns(@command, object)
311
311
  else
@@ -364,7 +364,7 @@ module Groonga
364
364
  end
365
365
  if @command[:values]
366
366
  values = Yajl::Parser.parse(@command[:values])
367
- if @command.columns.nil? and values.first.is_a?(Array)
367
+ if @command.columns.nil? and values.first.is_a?(::Array)
368
368
  header = values.shift
369
369
  @command.columns = header
370
370
  on_load_columns(@command, header)
@@ -380,7 +380,7 @@ module Groonga
380
380
  end
381
381
  else
382
382
  on_command(@command)
383
- reset
383
+ @command = nil
384
384
  end
385
385
  end
386
386
 
@@ -25,9 +25,26 @@ module Groonga
25
25
 
26
26
  class << self
27
27
  def parameter_names
28
- # TODO: Fill me
29
28
  [
30
- :table
29
+ :table,
30
+ :match_columns,
31
+ :query,
32
+ :filter,
33
+ :scorer,
34
+ :sortby,
35
+ :output_columns,
36
+ :offset,
37
+ :limit,
38
+ :drilldown,
39
+ :drilldown_sortby,
40
+ :drilldown_output_columns,
41
+ :drilldown_offset,
42
+ :drilldown_limit,
43
+ :cache,
44
+ :match_escalation_threshold,
45
+ :query_expansion,
46
+ :query_flags,
47
+ :query_expander,
31
48
  ]
32
49
  end
33
50
  end
@@ -31,6 +31,7 @@ module Groonga
31
31
  :key_type,
32
32
  :value_type,
33
33
  :default_tokenizer,
34
+ :normalizer,
34
35
  ]
35
36
  end
36
37
  end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Groonga
20
20
  module Command
21
- VERSION = "1.0.3"
21
+ VERSION = "1.0.4"
22
22
  end
23
23
  end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 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
+ class CommandFormatTest < Test::Unit::TestCase
20
+ class EscapeValueTest < self
21
+ test '\n' do
22
+ assert_equal('"\\n"', escape_value("\n"))
23
+ end
24
+
25
+ test '"' do
26
+ assert_equal('"\\""', escape_value("\""))
27
+ end
28
+
29
+ test "\\" do
30
+ assert_equal('"\\\\"', escape_value("\\"))
31
+ end
32
+
33
+ def escape_value(value)
34
+ Groonga::Command::Format::Command.escape_value(value)
35
+ end
36
+ end
37
+ end
@@ -21,10 +21,71 @@ class SelectCommandTest < Test::Unit::TestCase
21
21
 
22
22
  def test_ordered_argument
23
23
  table = "Users"
24
- command = parse("select", [table], :output_type => false)
24
+ match_columns = "name * 10 || description"
25
+ query = "groonga"
26
+ filter = "age >= 18"
27
+ scorer = "_score = age"
28
+ sortby = "_score"
29
+ output_columns = "_key, name"
30
+ offset = "10"
31
+ limit = "20"
32
+ drilldown = "name"
33
+ drilldown_sortby = "_nsubrecs"
34
+ drilldown_output_columns = "name, _nsubrecs"
35
+ drilldown_offset = "5"
36
+ drilldown_limit = "10"
37
+ cache = "no"
38
+ match_escalation_threshold = "-1"
39
+ query_expansion = "deprecated"
40
+ query_flags = "ALLOW_LEADING_NOT"
41
+ query_expander = "Terms.synonym"
42
+ command = parse("select",
43
+ [
44
+ table,
45
+ match_columns,
46
+ query,
47
+ filter,
48
+ scorer,
49
+ sortby,
50
+ output_columns,
51
+ offset,
52
+ limit,
53
+ drilldown,
54
+ drilldown_sortby,
55
+ drilldown_output_columns,
56
+ drilldown_offset,
57
+ drilldown_limit,
58
+ cache,
59
+ match_escalation_threshold,
60
+ query_expansion,
61
+ query_flags,
62
+ query_expander,
63
+ ],
64
+ :output_type => false)
25
65
 
26
66
  assert_instance_of(Groonga::Command::Select, command)
27
- assert_equal({:table => table}, command.arguments)
67
+ assert_equal({
68
+ :table => table,
69
+ :match_columns => match_columns,
70
+ :query => query,
71
+ :filter => filter,
72
+ :scorer => scorer,
73
+ :sortby => sortby,
74
+ :output_columns => output_columns,
75
+ :offset => offset,
76
+ :limit => limit,
77
+ :drilldown => drilldown,
78
+ :drilldown_sortby => drilldown_sortby,
79
+ :drilldown_output_columns => drilldown_output_columns,
80
+ :drilldown_offset => drilldown_offset,
81
+ :drilldown_limit => drilldown_limit,
82
+ :cache => cache,
83
+ :match_escalation_threshold => match_escalation_threshold,
84
+ :query_expansion => query_expansion,
85
+ :query_flags => query_flags,
86
+ :query_expander => query_expander,
87
+ },
88
+ command.arguments)
28
89
  end
29
90
 
30
91
  def test_scorer
@@ -26,8 +26,9 @@ class TableCreateCommandTest < Test::Unit::TestCase
26
26
  key_type = "ShortText"
27
27
  value_type = "UInt32"
28
28
  default_tokenizer = "TokenBigram"
29
+ normalizer = "NormalizerAuto"
29
30
 
30
- command = parse([name, flags, key_type, value_type, default_tokenizer])
31
+ command = parse([name, flags, key_type, value_type, default_tokenizer, normalizer])
31
32
  assert_instance_of(Groonga::Command::TableCreate, command)
32
33
  assert_equal({
33
34
  :name => name,
@@ -35,6 +36,7 @@ class TableCreateCommandTest < Test::Unit::TestCase
35
36
  :key_type => key_type,
36
37
  :value_type => value_type,
37
38
  :default_tokenizer => default_tokenizer,
39
+ :normalizer => normalizer,
38
40
  },
39
41
  command.arguments)
40
42
  end
data/test/test-parser.rb CHANGED
@@ -113,6 +113,24 @@ class ParserTest < Test::Unit::TestCase
113
113
  @parser << "status\n"
114
114
  assert_equal("status", parsed_command.name)
115
115
  end
116
+
117
+ def test_multi_lines
118
+ parsed_commands = []
119
+ @parser.on_command do |command|
120
+ parsed_commands << command
121
+ end
122
+
123
+ @parser << <<-COMMAND_LIST.chomp
124
+ table_list
125
+ status
126
+ COMMAND_LIST
127
+ assert_equal(["table_list"],
128
+ parsed_commands.collect(&:name))
129
+
130
+ @parser.finish
131
+ assert_equal(["table_list", "status"],
132
+ parsed_commands.collect(&:name))
133
+ end
116
134
  end
117
135
 
118
136
  class LoadTest < self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-23 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -151,45 +151,48 @@ files:
151
151
  - Gemfile
152
152
  - groonga-command.gemspec
153
153
  - .yardopts
154
- - lib/groonga/command/register.rb
155
- - lib/groonga/command/version.rb
156
- - lib/groonga/command/column-rename.rb
157
154
  - lib/groonga/command/truncate.rb
155
+ - lib/groonga/command/parser.rb
156
+ - lib/groonga/command/table-remove.rb
158
157
  - lib/groonga/command/load.rb
159
158
  - lib/groonga/command/delete.rb
160
- - lib/groonga/command/error.rb
161
- - lib/groonga/command/column-create.rb
159
+ - lib/groonga/command/base.rb
162
160
  - lib/groonga/command/suggest.rb
163
- - lib/groonga/command/table-remove.rb
161
+ - lib/groonga/command/error.rb
162
+ - lib/groonga/command/register.rb
163
+ - lib/groonga/command/version.rb
164
164
  - lib/groonga/command/column-remove.rb
165
+ - lib/groonga/command/column-rename.rb
166
+ - lib/groonga/command/dump.rb
165
167
  - lib/groonga/command/table-create.rb
168
+ - lib/groonga/command/format/command.rb
169
+ - lib/groonga/command/format/uri.rb
170
+ - lib/groonga/command/column-create.rb
166
171
  - lib/groonga/command/get.rb
167
- - lib/groonga/command/base.rb
168
- - lib/groonga/command/dump.rb
169
- - lib/groonga/command/table-rename.rb
170
172
  - lib/groonga/command/select.rb
171
- - lib/groonga/command/parser.rb
173
+ - lib/groonga/command/table-rename.rb
172
174
  - lib/groonga/command.rb
173
- - doc/text/lgpl-2.1.txt
174
175
  - doc/text/news.md
175
- - test/command/test-column-remove.rb
176
- - test/command/test-table-rename.rb
176
+ - doc/text/lgpl-2.1.txt
177
+ - test/groonga-command-test-utils.rb
178
+ - test/run-test.rb
177
179
  - test/command/test-table-create.rb
178
- - test/command/test-column-rename.rb
179
- - test/command/test-load.rb
180
- - test/command/test-suggest.rb
180
+ - test/command/test-dump.rb
181
+ - test/command/test-table-rename.rb
181
182
  - test/command/test-table-remove.rb
183
+ - test/command/test-truncate.rb
182
184
  - test/command/test-delete.rb
185
+ - test/command/test-select.rb
183
186
  - test/command/test-base.rb
184
187
  - test/command/test-column-create.rb
185
188
  - test/command/test-register.rb
186
- - test/command/test-select.rb
187
- - test/command/test-truncate.rb
188
- - test/command/test-dump.rb
189
189
  - test/command/test-get.rb
190
+ - test/command/test-suggest.rb
191
+ - test/command/format/test-command.rb
192
+ - test/command/test-column-rename.rb
193
+ - test/command/test-load.rb
194
+ - test/command/test-column-remove.rb
190
195
  - test/test-parser.rb
191
- - test/run-test.rb
192
- - test/groonga-command-test-utils.rb
193
196
  homepage: https://github.com/groonga/groonga-command
194
197
  licenses:
195
198
  - LGPLv2.1+
@@ -217,22 +220,23 @@ specification_version: 3
217
220
  summary: Groonga-command is a library to process [groonga](http://groonga.org/)'s
218
221
  command syntax. You can write a program to process groonga's command by using groonga-command.
219
222
  test_files:
220
- - test/command/test-column-remove.rb
221
- - test/command/test-table-rename.rb
223
+ - test/groonga-command-test-utils.rb
224
+ - test/run-test.rb
222
225
  - test/command/test-table-create.rb
223
- - test/command/test-column-rename.rb
224
- - test/command/test-load.rb
225
- - test/command/test-suggest.rb
226
+ - test/command/test-dump.rb
227
+ - test/command/test-table-rename.rb
226
228
  - test/command/test-table-remove.rb
229
+ - test/command/test-truncate.rb
227
230
  - test/command/test-delete.rb
231
+ - test/command/test-select.rb
228
232
  - test/command/test-base.rb
229
233
  - test/command/test-column-create.rb
230
234
  - test/command/test-register.rb
231
- - test/command/test-select.rb
232
- - test/command/test-truncate.rb
233
- - test/command/test-dump.rb
234
235
  - test/command/test-get.rb
236
+ - test/command/test-suggest.rb
237
+ - test/command/format/test-command.rb
238
+ - test/command/test-column-rename.rb
239
+ - test/command/test-load.rb
240
+ - test/command/test-column-remove.rb
235
241
  - test/test-parser.rb
236
- - test/run-test.rb
237
- - test/groonga-command-test-utils.rb
238
242
  has_rdoc: