groonga-client 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6acb75bd146da352188103e7a1970a8a219200c5
4
- data.tar.gz: f91de40970d46772c874b18558fa9ce8f5383c0c
3
+ metadata.gz: 525ea4e0715bed716fde7af9813a55e0d0b90fd6
4
+ data.tar.gz: ff541cecc8a018112201af5af4fc978f32578f8d
5
5
  SHA512:
6
- metadata.gz: e153df284b448608874783c83582fdfada42e13c58d265eda16957cc853999c49128dd2f3e44325eb43befbbf78cb3df32d63613421da90899475429bf47074c
7
- data.tar.gz: 06c18591b44b11e1ddcaaf0789dd0b23631797d8e7c4175a4022360954e4ca74cd332bc4bb6d73dde4762fd06fea5bf9e616d36dff81dd72c9f57898a9aef8ba
6
+ metadata.gz: 1b6db2d64ce83681ddb33181c9289944f5c79d13b2df9127bdbc3280d584ad4b7cf6afdede3ad20b45d85d31c4af9604a80496a400f481cfc8b05fc58f2a5ff1
7
+ data.tar.gz: c9e40baebc159097c8b3b0196f0964050d38e515cc7957a1f22f4d6f05f449e567d1d39656fb7822377873086505e4215e1c0fb3de9e54dd93c7ef2a4070f38d
data/doc/text/news.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.2.2 - 2016-03-22
4
+
5
+ ### Improvements
6
+
7
+ * response: Supported `lock_clear` command.
8
+
9
+ * response: Supported `schema` command partially.
10
+
11
+ ### Fixes
12
+
13
+ * Fixed a bug that `Groonga::Command` isn't accepted.
14
+
3
15
  ## 0.2.1 - 2016-03-21
4
16
 
5
17
  ### Improvements
@@ -46,6 +46,7 @@ Gem::Specification.new do |spec|
46
46
 
47
47
  spec.add_runtime_dependency("gqtp", ">= 1.0.4")
48
48
  spec.add_runtime_dependency("groonga-command", ">= 1.2.0")
49
+ spec.add_runtime_dependency("hashie")
49
50
 
50
51
  spec.add_development_dependency("bundler")
51
52
  spec.add_development_dependency("rake")
@@ -165,7 +165,7 @@ module Groonga
165
165
  end
166
166
 
167
167
  def execute(command_or_name, parameters={}, &block)
168
- if command_or_name.is_a?(Command)
168
+ if command_or_name.is_a?(Groonga::Command::Base)
169
169
  command = command_or_name
170
170
  else
171
171
  command_name = command_or_name
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2014-2016 Kouhei Sutou <kou@clear-code.com>
4
2
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # This library is free software; you can redistribute it and/or
@@ -17,25 +15,26 @@
17
15
  # License along with this library; if not, write to the Free Software
18
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
 
20
- require "groonga/client/response/cache_limit"
18
+ require "groonga/client/response/cache-limit"
21
19
  require "groonga/client/response/check"
22
- require "groonga/client/response/clearlock"
23
- require "groonga/client/response/column_create"
24
- require "groonga/client/response/column_list"
25
- require "groonga/client/response/column_remove"
26
- require "groonga/client/response/column_rename"
20
+ require "groonga/client/response/column-create"
21
+ require "groonga/client/response/column-list"
22
+ require "groonga/client/response/column-remove"
23
+ require "groonga/client/response/column-rename"
27
24
  require "groonga/client/response/defrag"
28
25
  require "groonga/client/response/delete"
29
26
  require "groonga/client/response/dump"
30
27
  require "groonga/client/response/error"
31
28
  require "groonga/client/response/load"
32
- require "groonga/client/response/log_level"
33
- require "groonga/client/response/log_put"
34
- require "groonga/client/response/log_reopen"
29
+ require "groonga/client/response/lock-clear"
30
+ require "groonga/client/response/log-level"
31
+ require "groonga/client/response/log-put"
32
+ require "groonga/client/response/log-reopen"
35
33
  require "groonga/client/response/quit"
36
34
  require "groonga/client/response/register"
35
+ require "groonga/client/response/schema"
37
36
  require "groonga/client/response/select"
38
37
  require "groonga/client/response/status"
39
- require "groonga/client/response/table_create"
40
- require "groonga/client/response/table_list"
41
- require "groonga/client/response/table_remove"
38
+ require "groonga/client/response/table-create"
39
+ require "groonga/client/response/table-list"
40
+ require "groonga/client/response/table-remove"
@@ -18,9 +18,10 @@
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
20
  require "rexml/document"
21
-
22
21
  require "json"
23
22
 
23
+ require "hashie"
24
+
24
25
  module Groonga
25
26
  class Client
26
27
  module Response
@@ -1,6 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
2
+ # Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
4
3
  #
5
4
  # This library is free software; you can redistribute it and/or
6
5
  # modify it under the terms of the GNU Lesser General Public
@@ -21,7 +20,9 @@ require "groonga/client/response/base"
21
20
  module Groonga
22
21
  class Client
23
22
  module Response
24
- class ClearLock < Base
23
+ class LockClear < Base
24
+ Response.register("lock_clear", self)
25
+ # For backward compatibility
25
26
  Response.register("clearlock", self)
26
27
  end
27
28
  end
@@ -0,0 +1,151 @@
1
+ # Copyright (C) 2016 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
+ require "groonga/client/response/base"
18
+
19
+ module Groonga
20
+ class Client
21
+ module Response
22
+ # The response class for `schema` command.
23
+ #
24
+ # @since 0.2.2
25
+ class Schema < Base
26
+ Response.register("schema", self)
27
+
28
+ # @return [Hash<String, Type>] Key is type name and
29
+ # value is the definition of the type.
30
+ #
31
+ # @since 0.2.2
32
+ def types
33
+ @types ||= HashValueConverter.convert(@body["types"]) do |raw_type|
34
+ Type[raw_type]
35
+ end
36
+ end
37
+
38
+ # @return [Hash<String, Tokenizer>] Key is tokenizer name and
39
+ # value is the definition of the tokenizer.
40
+ #
41
+ # @since 0.2.2
42
+ def tokenizers
43
+ @tokenizers ||= HashValueConverter.convert(@body["tokenizers"]) do |tokenizer|
44
+ Tokenizer[tokenizer]
45
+ end
46
+ end
47
+
48
+ # @return [Hash<String, Table>] Key is table name and value is the
49
+ # definition of the table.
50
+ #
51
+ # @since 0.2.2
52
+ def tables
53
+ @tables ||= HashValueConverter.convert(@body["tables"]) do |raw_table|
54
+ table = Table.new(self)
55
+ raw_table.each do |key, value|
56
+ table[key] = value
57
+ end
58
+ table
59
+ end
60
+ end
61
+
62
+ module HashValueConverter
63
+ class << self
64
+ def convert(hash)
65
+ converted = {}
66
+ hash.each do |key, value|
67
+ converted[key] = yield(value)
68
+ end
69
+ converted
70
+ end
71
+ end
72
+ end
73
+
74
+ class Type < Hash
75
+ include Hashie::Extensions::MethodAccess
76
+ end
77
+
78
+ class Tokenizer < Hash
79
+ include Hashie::Extensions::MethodAccess
80
+ end
81
+
82
+ class KeyType < Hash
83
+ include Hashie::Extensions::MethodAccess
84
+ end
85
+
86
+ class ValueType < Hash
87
+ include Hashie::Extensions::MethodAccess
88
+ end
89
+
90
+ class Column < Hash
91
+ include Hashie::Extensions::MethodAccess
92
+
93
+ def initialize(schema, properties)
94
+ @schema = schema
95
+ super()
96
+ properties.each do |key, value|
97
+ self[key] = value
98
+ end
99
+ end
100
+ end
101
+
102
+ class Table < Hash
103
+ include Hashie::Extensions::MethodAccess
104
+
105
+ def initialize(schema)
106
+ @schema = schema
107
+ super()
108
+ end
109
+
110
+ def []=(key, value)
111
+ case key.to_sym
112
+ when :key_type
113
+ super(key, coerce_key_type(value))
114
+ when :tokenizer
115
+ super(key, coerce_tokenzer(value))
116
+ when :columns
117
+ super(key, coerce_columns(value))
118
+ else
119
+ super
120
+ end
121
+ end
122
+
123
+ private
124
+ def coerce_key_type(raw_key_type)
125
+ if raw_key_type.nil?
126
+ nil
127
+ elsif raw_key_type["type"] == "type"
128
+ @schema.types[raw_key_type["name"]]
129
+ else
130
+ @schema.tables[raw_key_type["name"]]
131
+ end
132
+ end
133
+
134
+ def coerce_tokenizer(raw_tokenizer)
135
+ if raw_tokenizer.nil?
136
+ nil
137
+ else
138
+ @schema.tokenizers[raw_tokenizer["name"]]
139
+ end
140
+ end
141
+
142
+ def coerce_columns(raw_columns)
143
+ HashValueConverter.convert(raw_columns) do |raw_column|
144
+ Column.new(@schema, raw_column)
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  class Client
19
- VERSION = "0.2.1"
19
+ VERSION = "0.2.2"
20
20
  end
21
21
  end
@@ -0,0 +1,83 @@
1
+ # Copyright (C) 2016 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
+ require "response/helper"
18
+
19
+ class TestResponseSchema < Test::Unit::TestCase
20
+ class TestParseRawResponse < self
21
+ include TestResponseHelper
22
+
23
+ def test_select
24
+ header = [0, 1372430096.70991, 0.000522851943969727]
25
+ body = {}
26
+ raw_response = [header, body].to_json
27
+
28
+ response = parse_raw_response("schema", raw_response)
29
+ assert_equal(Groonga::Client::Response::Schema, response.class)
30
+ end
31
+ end
32
+
33
+ class TestBody < self
34
+ def setup
35
+ @command = Groonga::Command::Base.new("schema", {})
36
+ end
37
+
38
+ def create_response(body)
39
+ header = [0, 1372430096.70991, 0.000522851943969727]
40
+ Groonga::Client::Response::Schema.new(@command, header, body)
41
+ end
42
+
43
+ class TestTables < self
44
+ def test_key_type
45
+ body = {
46
+ "types" => {
47
+ "ShortText" => {
48
+ "name" => "ShortText",
49
+ },
50
+ },
51
+ "tables" => {
52
+ "Users" => {
53
+ "key_type" => {
54
+ "name" => "ShortText",
55
+ "type" => "type",
56
+ },
57
+ }
58
+ }
59
+ }
60
+ response = create_response(body)
61
+ assert_equal("ShortText",
62
+ response.tables["Users"].key_type.name)
63
+ end
64
+
65
+ def test_columns
66
+ body = {
67
+ "tables" => {
68
+ "Users" => {
69
+ "columns" => {
70
+ "age" => {
71
+ "name" => "age",
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ response = create_response(body)
78
+ assert_equal("age",
79
+ response.tables["Users"].columns["age"].name)
80
+ end
81
+ end
82
+ end
83
+ end
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.2.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: hashie
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: bundler
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -186,28 +200,29 @@ files:
186
200
  - lib/groonga/client/protocol/http/thread.rb
187
201
  - lib/groonga/client/response.rb
188
202
  - lib/groonga/client/response/base.rb
189
- - lib/groonga/client/response/cache_limit.rb
203
+ - lib/groonga/client/response/cache-limit.rb
190
204
  - lib/groonga/client/response/check.rb
191
- - lib/groonga/client/response/clearlock.rb
192
- - lib/groonga/client/response/column_create.rb
193
- - lib/groonga/client/response/column_list.rb
194
- - lib/groonga/client/response/column_remove.rb
195
- - lib/groonga/client/response/column_rename.rb
205
+ - lib/groonga/client/response/column-create.rb
206
+ - lib/groonga/client/response/column-list.rb
207
+ - lib/groonga/client/response/column-remove.rb
208
+ - lib/groonga/client/response/column-rename.rb
196
209
  - lib/groonga/client/response/defrag.rb
197
210
  - lib/groonga/client/response/delete.rb
198
211
  - lib/groonga/client/response/dump.rb
199
212
  - lib/groonga/client/response/error.rb
200
213
  - lib/groonga/client/response/load.rb
201
- - lib/groonga/client/response/log_level.rb
202
- - lib/groonga/client/response/log_put.rb
203
- - lib/groonga/client/response/log_reopen.rb
214
+ - lib/groonga/client/response/lock-clear.rb
215
+ - lib/groonga/client/response/log-level.rb
216
+ - lib/groonga/client/response/log-put.rb
217
+ - lib/groonga/client/response/log-reopen.rb
204
218
  - lib/groonga/client/response/quit.rb
205
219
  - lib/groonga/client/response/register.rb
220
+ - lib/groonga/client/response/schema.rb
206
221
  - lib/groonga/client/response/select.rb
207
222
  - lib/groonga/client/response/status.rb
208
- - lib/groonga/client/response/table_create.rb
209
- - lib/groonga/client/response/table_list.rb
210
- - lib/groonga/client/response/table_remove.rb
223
+ - lib/groonga/client/response/table-create.rb
224
+ - lib/groonga/client/response/table-list.rb
225
+ - lib/groonga/client/response/table-remove.rb
211
226
  - lib/groonga/client/script-syntax.rb
212
227
  - lib/groonga/client/version.rb
213
228
  - test/protocol/test-gqtp.rb
@@ -216,6 +231,7 @@ files:
216
231
  - test/response/test-base.rb
217
232
  - test/response/test-column-list.rb
218
233
  - test/response/test-error.rb
234
+ - test/response/test-schema.rb
219
235
  - test/response/test-select.rb
220
236
  - test/response/test-status.rb
221
237
  - test/response/test-table-create.rb
@@ -265,6 +281,7 @@ test_files:
265
281
  - test/response/test-error.rb
266
282
  - test/response/test-table-list.rb
267
283
  - test/response/test-status.rb
284
+ - test/response/test-schema.rb
268
285
  - test/response/test-select.rb
269
286
  - test/response/test-table-create.rb
270
287
  - test/response/test-table-remove.rb