groonga-client 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 227bf7a979643ac2f17b20d32b4b3ed0129f8321
4
- data.tar.gz: 6e7b2e2451b0d0bf59313a639f2c7c819b4aba7b
3
+ metadata.gz: f56e626e8d1f3ee3b00e41b67707cb96f92e7c88
4
+ data.tar.gz: ad74c24105a448472102e6c13a47c9fe9e2b0678
5
5
  SHA512:
6
- metadata.gz: 842ff5602d19852b2ebceb64c470efe15eb48a85ef24c539dfd3e7e09458139a9cba3c899cffce26a29cb25cd2c771f815550aaf283c69f62d740161122e0504
7
- data.tar.gz: 66bd127398051d6314c7df147688297244dd609c89b7a06eca59351634d4f7c2e06676eb0bb695af55a34553b7a24162e48c28c2eb67a98b77401a75cd741592
6
+ metadata.gz: 424579d18aa485f0615c7b0d2eb113f1acd35d5889a8665abe5200eadd05ac6a0273567105d79807d8957b9ad9e8409c1a4668c94a43c5e8e6e292bf317a47f6
7
+ data.tar.gz: fef4befdfa5f7ab2f61c39d1e23dae58b9f0e2d095ae24388d5a214e051b027a6dae5e8c07074217748de3ff258484ced5eb9750bada21a83565c588fec10aac
@@ -1,5 +1,19 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.4.2 - 2016-03-09
4
+
5
+ ### Improvements
6
+
7
+ * `Groonga::Client#request`: Added a new generic request method.
8
+
9
+ * `Groonga::Client::Request::Generic#flags_parameter`: Added a
10
+ convenience method to add a flags parameter such as
11
+ `table_create`'s `flags` parameter.
12
+
13
+ * `Groonga::Client::Request::Generic#values_parameter`: Added a
14
+ convenience method to add a parameter that takes multiple values
15
+ such as `select`'s `output_columns` parameter.
16
+
3
17
  ## 0.4.1 - 2016-02-07
4
18
 
5
19
  ### Improvements
@@ -176,6 +176,28 @@ module Groonga
176
176
  execute_command(command, &block)
177
177
  end
178
178
 
179
+ def request(name)
180
+ command_name_module = Module.new do
181
+ define_method :command_name do
182
+ name
183
+ end
184
+ end
185
+
186
+ client = self
187
+ open_client_module = Module.new do
188
+ define_method :open_client do |&block|
189
+ block.call(client)
190
+ end
191
+ end
192
+
193
+ extensions = [
194
+ command_name_module,
195
+ open_client_module,
196
+ ]
197
+ request_class = Request.find(name)
198
+ request_class.new(nil, extensions)
199
+ end
200
+
179
201
  def method_missing(name, *args, &block)
180
202
  if groonga_command_name?(name)
181
203
  execute(name, *args, &block)
@@ -14,9 +14,26 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
+ module Groonga
18
+ class Client
19
+ module Request
20
+ @@requests = {}
21
+ class << self
22
+ def register(request_class)
23
+ @@requests[request_class.command_name] = request_class
24
+ end
25
+
26
+ def find(name)
27
+ @@requests[name.to_s] || Generic
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
17
34
  require "groonga/client/script-syntax"
18
35
 
19
- require "groonga/client/request/base"
20
36
  require "groonga/client/request/error"
37
+ require "groonga/client/request/generic"
21
38
 
22
39
  require "groonga/client/request/select"
@@ -17,13 +17,17 @@
17
17
  module Groonga
18
18
  class Client
19
19
  module Request
20
- class Base
20
+ class Generic
21
21
  def initialize(parameters=nil, extensions=[])
22
22
  @parameters = parameters
23
23
  @extensions = extensions
24
24
  extend(*@extensions) unless @extensions.empty?
25
25
  end
26
26
 
27
+ def command_name
28
+ self.class.command_name
29
+ end
30
+
27
31
  def response
28
32
  @reponse ||= create_response
29
33
  end
@@ -33,6 +37,26 @@ module Groonga
33
37
  RequestParameter.new(name, value))
34
38
  end
35
39
 
40
+ def flags_parameter(name_or_names, value)
41
+ if name_or_names.is_a?(Array)
42
+ names = name_or_names
43
+ else
44
+ names = [name_or_names]
45
+ end
46
+ add_parameter(OverwriteMerger,
47
+ FlagsParameter.new(names, value))
48
+ end
49
+
50
+ def values_parameter(name_or_names, values)
51
+ if name_or_names.is_a?(Array)
52
+ names = name_or_names
53
+ else
54
+ names = [name_or_names]
55
+ end
56
+ add_parameter(OverwriteMerger,
57
+ ValuesParameter.new(names, values))
58
+ end
59
+
36
60
  def to_parameters
37
61
  if @parameters.nil?
38
62
  {}
@@ -62,7 +86,7 @@ module Groonga
62
86
 
63
87
  def create_response
64
88
  open_client do |client|
65
- response = client.execute(self.class.command_name, to_parameters)
89
+ response = client.execute(command_name, to_parameters)
66
90
  raise ErrorResponse.new(response) unless response.success?
67
91
  response
68
92
  end
@@ -168,7 +192,19 @@ module Groonga
168
192
 
169
193
  class OverwriteMerger < ParameterMerger
170
194
  def to_parameters
171
- @parameters1.to_parameters.merge(@parameters2.to_parameters)
195
+ if @parameters1.nil?
196
+ if @parameters2.nil?
197
+ {}
198
+ else
199
+ @parameters2.to_parameters
200
+ end
201
+ else
202
+ if @parameters2.nil?
203
+ @parameters1.to_parameters
204
+ else
205
+ @parameters1.to_parameters.merge(@parameters2.to_parameters)
206
+ end
207
+ end
172
208
  end
173
209
  end
174
210
  end
@@ -17,7 +17,7 @@
17
17
  module Groonga
18
18
  class Client
19
19
  module Request
20
- class Select < Base
20
+ class Select < Generic
21
21
  include Enumerable
22
22
 
23
23
  class << self
@@ -26,6 +26,8 @@ module Groonga
26
26
  end
27
27
  end
28
28
 
29
+ Request.register(self)
30
+
29
31
  def initialize(table_or_parameters, extensions=[])
30
32
  if table_or_parameters.respond_to?(:to_parameters)
31
33
  parameters = table_or_parameters
@@ -36,9 +38,8 @@ module Groonga
36
38
  super(parameters, extensions)
37
39
  end
38
40
 
39
- def match_columns(value)
40
- add_parameter(OverwriteMerger,
41
- ValuesParameter.new([:match_columns], value))
41
+ def match_columns(values)
42
+ values_parameter([:match_columns], values)
42
43
  end
43
44
 
44
45
  def query(value)
@@ -158,9 +159,8 @@ module Groonga
158
159
  @label = label
159
160
  end
160
161
 
161
- def keys(value)
162
- add_parameter(OverwriteMerger,
163
- ValuesParameter.new([:"#{prefix}keys"], value))
162
+ def keys(values)
163
+ @request.values_parameter([:"#{prefix}keys"], values)
164
164
  end
165
165
 
166
166
  def sort_keys(value)
@@ -184,8 +184,7 @@ module Groonga
184
184
  end
185
185
 
186
186
  def calc_types(value)
187
- add_parameter(OverwriteMerger,
188
- FlagsParameter.new([:"#{prefix}calc_types"], value))
187
+ @request.flags_parameter(:"#{prefix}calc_types", value)
189
188
  end
190
189
 
191
190
  def calc_target(value)
@@ -219,8 +218,7 @@ module Groonga
219
218
  end
220
219
 
221
220
  def flags(value)
222
- add_parameter(OverwriteMerger,
223
- FlagsParameter.new([:"#{prefix}flags"], value))
221
+ @request.flags_parameter(:"#{prefix}flags", value)
224
222
  end
225
223
 
226
224
  def value(expression, values=nil)
@@ -263,9 +261,8 @@ module Groonga
263
261
  # request object.
264
262
  #
265
263
  # @since 0.4.1
266
- def group_keys(value)
267
- add_parameter(OverwriteMerger,
268
- ValuesParameter.new([:"#{prefix}group_keys"], value))
264
+ def group_keys(values)
265
+ @request.values_parameter([:"#{prefix}group_keys"], values)
269
266
  end
270
267
 
271
268
  private
@@ -202,7 +202,8 @@ module Groonga
202
202
  when :indexes
203
203
  super(key, coerce_indexes(value))
204
204
  when :value_type
205
- super(key, ValueType.new(value))
205
+ value = ValueType.new(value) unless value.nil?
206
+ super(key, value)
206
207
  else
207
208
  super
208
209
  end
@@ -140,7 +140,7 @@ module Groonga
140
140
  break
141
141
  else
142
142
  begin
143
- pid = Process.waitpid(@pid, Process::WNOHANG)
143
+ Process.waitpid(@pid, Process::WNOHANG)
144
144
  rescue SystemCallError
145
145
  @pid = nil
146
146
  break
@@ -150,10 +150,6 @@ module Groonga
150
150
  end
151
151
 
152
152
  def wait_groonga_shutdown
153
- # TODO: Remove me when Groonga 6.0.1 has been released.
154
- # Workaround to shutdown as soon as possible.
155
- groonga_server_running?
156
-
157
153
  n_retried = 0
158
154
  while n_retried <= 20
159
155
  n_retried += 1
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  class Client
19
- VERSION = "0.4.1"
19
+ VERSION = "0.4.2"
20
20
  end
21
21
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,10 +14,10 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- class TestRequestBase < Test::Unit::TestCase
17
+ class TestRequestGeneric < Test::Unit::TestCase
18
18
  sub_test_case "#extensions" do
19
19
  setup do
20
- @request = Groonga::Client::Request::Base.new("status")
20
+ @request = Groonga::Client::Request::Generic.new("status")
21
21
  end
22
22
 
23
23
  test "Module" do
@@ -0,0 +1,48 @@
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ class TestRequestMerger < Test::Unit::TestCase
18
+ sub_test_case "OverwriteMerger" do
19
+ def merge(parameters1, parameters2)
20
+ klass = Groonga::Client::Request::OverwriteMerger
21
+ klass.new(parameters1, parameters2).to_parameters
22
+ end
23
+
24
+ def param(name, value)
25
+ Groonga::Client::Request::RequestParameter.new(name, value)
26
+ end
27
+
28
+ test "(nil, nil)" do
29
+ assert_equal({}, merge(nil, nil))
30
+ end
31
+
32
+ test "(nil, parameter)" do
33
+ assert_equal({"name" => "value"},
34
+ merge(nil, param("name", "value")))
35
+ end
36
+
37
+ test "(parameter, nil)" do
38
+ assert_equal({"name" => "value"},
39
+ merge(param("name", "value"), nil))
40
+ end
41
+
42
+ test "(parameter, parameter)" do
43
+ assert_equal({"name" => "value2"},
44
+ merge(param("name", "value1"),
45
+ param("name", "value2")))
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
2
- # Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
5
5
  # modify it under the terms of the GNU Lesser General Public
@@ -300,6 +300,15 @@ JSON
300
300
  end
301
301
  end
302
302
 
303
+ module RequestTests
304
+ def test_generic
305
+ expected_response = {"key" => "value"}
306
+ stub_response(expected_response.to_json)
307
+ response = client.request(:status).response
308
+ assert_equal(expected_response, response.body)
309
+ end
310
+ end
311
+
303
312
  module Tests
304
313
  include Utils
305
314
  include Assertions
@@ -310,6 +319,7 @@ JSON
310
319
  include OpenTests
311
320
  include LoadTests
312
321
  include DefaultOptionsTests
322
+ include RequestTests
313
323
  end
314
324
 
315
325
  class TestGQTP < self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-07 00:00:00.000000000 Z
13
+ date: 2017-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gqtp
@@ -187,8 +187,8 @@ files:
187
187
  - lib/groonga/client/protocol/http/synchronous.rb
188
188
  - lib/groonga/client/protocol/http/thread.rb
189
189
  - lib/groonga/client/request.rb
190
- - lib/groonga/client/request/base.rb
191
190
  - lib/groonga/client/request/error.rb
191
+ - lib/groonga/client/request/generic.rb
192
192
  - lib/groonga/client/request/select.rb
193
193
  - lib/groonga/client/response.rb
194
194
  - lib/groonga/client/response/base.rb
@@ -229,7 +229,8 @@ files:
229
229
  - test/request/select/test-output-columns-parameter.rb
230
230
  - test/request/select/test-sort-keys-parameter.rb
231
231
  - test/request/select/test-values-parameter.rb
232
- - test/request/test-base.rb
232
+ - test/request/test-generic.rb
233
+ - test/request/test-merger.rb
233
234
  - test/request/test-select.rb
234
235
  - test/response/helper.rb
235
236
  - test/response/test-base.rb
@@ -283,7 +284,8 @@ test_files:
283
284
  - test/request/select/test-output-columns-parameter.rb
284
285
  - test/request/select/test-values-parameter.rb
285
286
  - test/request/select/test-filter-equal-parameter.rb
286
- - test/request/test-base.rb
287
+ - test/request/test-merger.rb
288
+ - test/request/test-generic.rb
287
289
  - test/request/test-select.rb
288
290
  - test/test-command.rb
289
291
  - test/protocol/test-gqtp.rb