rroonga 6.0.0 → 6.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
+ /*
3
+ Copyright (C) 2016 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 version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ /*
22
+ * Document-class: Groonga::RequestTimerID
23
+ *
24
+ * This class represents request timer ID. It's used with request timer.
25
+ */
26
+
27
+ VALUE rb_cGrnRequestTimerID;
28
+
29
+ static rb_data_type_t data_type = {
30
+ "Groonga::RequestTimeID",
31
+ {
32
+ NULL,
33
+ NULL,
34
+ NULL,
35
+ },
36
+ NULL,
37
+ NULL,
38
+ 0
39
+ };
40
+
41
+ void *
42
+ rb_grn_request_timer_id_from_ruby_object (VALUE rb_id)
43
+ {
44
+ if (NIL_P(rb_id)) {
45
+ return NULL;
46
+ } else {
47
+ void *id;
48
+ TypedData_Get_Struct(rb_id, void *, &data_type, id);
49
+ return id;
50
+ }
51
+ }
52
+
53
+ VALUE
54
+ rb_grn_request_timer_id_to_ruby_object (void *id)
55
+ {
56
+ return TypedData_Wrap_Struct(rb_cGrnRequestTimerID, &data_type, id);
57
+ }
58
+
59
+ void
60
+ rb_grn_init_request_timer_id (VALUE mGrn)
61
+ {
62
+ rb_cGrnRequestTimerID =
63
+ rb_define_class_under(mGrn, "RequestTimerID", rb_cData);
64
+ }
@@ -0,0 +1,155 @@
1
+ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
+ /*
3
+ Copyright (C) 2016 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 version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ /*
22
+ * Document-module: Groonga::RequestTimer
23
+ *
24
+ * This module provides API for canceling requests after the specified
25
+ * time.
26
+ */
27
+
28
+ VALUE rb_mGrnRequestTimer;
29
+
30
+ /*
31
+ * Registers a request with timeout. If the request isn't finished
32
+ * after the specified timeout, the request is canceled.
33
+ *
34
+ * @example Register a request that will be timed out after 2.9 seconds
35
+ * request_id = "request-29"
36
+ * timeout_in_second = 2.9
37
+ * Groonga::RequestTimer.register(request_id, timeout_in_second)
38
+ *
39
+ * @overload register(request_id, timeout=nil)
40
+ * @param request_id [String] The ID of request to be registered.
41
+ * @param timeout (nil) [Float, nil] The timeout in second. If
42
+ * `timeout` is `nil`, {Groonga::RequestTimer.default_timeout} is
43
+ * used.
44
+ * @return [Groonga::RequestTimerID] The ID of the request timer.
45
+ *
46
+ * @since 6.0.2
47
+ */
48
+ static VALUE
49
+ rb_grn_request_timer_s_register (int argc, VALUE *argv, VALUE module)
50
+ {
51
+ VALUE rb_request_id;
52
+ VALUE rb_timeout;
53
+ const char *request_id;
54
+ unsigned int request_id_size;
55
+ double timeout;
56
+ void *timer_id;
57
+
58
+ rb_scan_args(argc, argv, "11", &rb_request_id, &rb_timeout);
59
+
60
+ request_id = StringValuePtr(rb_request_id);
61
+ request_id_size = RSTRING_LEN(rb_request_id);
62
+ if (NIL_P(rb_timeout)) {
63
+ timeout = grn_get_default_request_timeout();
64
+ } else {
65
+ timeout = NUM2DBL(rb_timeout);
66
+ }
67
+ timer_id = grn_request_timer_register(request_id, request_id_size, timeout);
68
+
69
+ return GRN_REQUEST_TIMER_ID2RVAL(timer_id);
70
+ }
71
+
72
+ /*
73
+ * Unregisters the specified request timer.
74
+ *
75
+ * @example Unregister a request timer by ID
76
+ * timer_id = Groonga::RequestTimer.register("request-29", 2.9)
77
+ * Groonga::RequestTimer.unregister(timer_id)
78
+ *
79
+ * @overload unregister(timer_id)
80
+ * @param timer_id [Groonga::RequestTimerID] The ID of request timer
81
+ * to be unregistered.
82
+ * @return [void]
83
+ *
84
+ * @since 6.0.2
85
+ */
86
+ static VALUE
87
+ rb_grn_request_timer_s_unregister (VALUE module, VALUE rb_timer_id)
88
+ {
89
+ void *timer_id;
90
+
91
+ timer_id = RVAL2GRN_REQUEST_TIMER_ID(rb_timer_id);
92
+ grn_request_timer_unregister(timer_id);
93
+
94
+ return Qnil;
95
+ }
96
+
97
+ /*
98
+ * Gets the default timeout used by request timer.
99
+ *
100
+ * @example Gets the default timeout
101
+ * Groonga::RequestTimer.default_timeout
102
+ *
103
+ * @overload default_timeout
104
+ * @return [Float] The default timeout used by request timer.
105
+ *
106
+ * @since 6.0.2
107
+ */
108
+ static VALUE
109
+ rb_grn_request_timer_s_get_default_timeout (VALUE module)
110
+ {
111
+ double timeout;
112
+
113
+ timeout = grn_get_default_request_timeout();
114
+
115
+ return rb_float_new(timeout);
116
+ }
117
+
118
+ /*
119
+ * Sets the default timeout used by request timer.
120
+ *
121
+ * @example Sets the default timeout
122
+ * Groonga::RequestTimer.default_timeout = 2.9
123
+ *
124
+ * @overload default_timeout=(timeout)
125
+ * @return [Float] The default timeout used by request timer. If
126
+ * `timeout` is `0.0`, the default timeout is disabled.
127
+ * @return [void]
128
+ *
129
+ * @since 6.0.2
130
+ */
131
+ static VALUE
132
+ rb_grn_request_timer_s_set_default_timeout (VALUE module, VALUE rb_timeout)
133
+ {
134
+ double timeout;
135
+
136
+ timeout = NUM2DBL(rb_timeout);
137
+ grn_set_default_request_timeout(timeout);
138
+
139
+ return Qnil;
140
+ }
141
+
142
+ void
143
+ rb_grn_init_request_timer (VALUE mGrn)
144
+ {
145
+ rb_mGrnRequestTimer = rb_define_module_under(mGrn, "RequestTimer");
146
+
147
+ rb_define_singleton_method(rb_mGrnRequestTimer, "register",
148
+ rb_grn_request_timer_s_register, -1);
149
+ rb_define_singleton_method(rb_mGrnRequestTimer, "unregister",
150
+ rb_grn_request_timer_s_unregister, 1);
151
+ rb_define_singleton_method(rb_mGrnRequestTimer, "default_timeout",
152
+ rb_grn_request_timer_s_get_default_timeout, 0);
153
+ rb_define_singleton_method(rb_mGrnRequestTimer, "default_timeout=",
154
+ rb_grn_request_timer_s_set_default_timeout, 1);
155
+ }
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
4
4
 
5
5
  This library is free software; you can redistribute it and/or
6
6
  modify it under the terms of the GNU Lesser General Public
@@ -173,6 +173,18 @@ rb_grn_type_variable_size_p (VALUE self)
173
173
  return CBOOL2RVAL(type->header.flags & GRN_OBJ_KEY_VAR_SIZE);
174
174
  }
175
175
 
176
+ static VALUE
177
+ rb_grn_type_builtin_p (VALUE self)
178
+ {
179
+ grn_ctx *context = NULL;
180
+ grn_obj *type;
181
+ grn_id id;
182
+
183
+ type = RVAL2GRNOBJECT(self, &context);
184
+ id = grn_obj_id(context, type);
185
+ return CBOOL2RVAL(grn_type_id_is_builtin(context, id));
186
+ }
187
+
176
188
  static VALUE
177
189
  rb_grn_type_unsigned_integer_p (VALUE self)
178
190
  {
@@ -217,6 +229,30 @@ rb_grn_type_geo_point_p (VALUE self)
217
229
  return CBOOL2RVAL(key_type == GRN_OBJ_KEY_GEO_POINT);
218
230
  }
219
231
 
232
+ static VALUE
233
+ rb_grn_type_text_family_p (VALUE self)
234
+ {
235
+ grn_ctx *context = NULL;
236
+ grn_obj *type;
237
+ grn_id id;
238
+
239
+ type = RVAL2GRNOBJECT(self, &context);
240
+ id = grn_obj_id(context, type);
241
+ return CBOOL2RVAL(grn_type_id_is_text_family(context, id));
242
+ }
243
+
244
+ static VALUE
245
+ rb_grn_type_number_family_p (VALUE self)
246
+ {
247
+ grn_ctx *context = NULL;
248
+ grn_obj *type;
249
+ grn_id id;
250
+
251
+ type = RVAL2GRNOBJECT(self, &context);
252
+ id = grn_obj_id(context, type);
253
+ return CBOOL2RVAL(grn_type_id_is_number_family(context, id));
254
+ }
255
+
220
256
  void
221
257
  rb_grn_init_type (VALUE mGrn)
222
258
  {
@@ -229,6 +265,9 @@ rb_grn_init_type (VALUE mGrn)
229
265
  rb_define_method(rb_cGrnType, "variable_size?",
230
266
  rb_grn_type_variable_size_p, 0);
231
267
 
268
+ rb_define_method(rb_cGrnType, "builtin?",
269
+ rb_grn_type_builtin_p, 0);
270
+
232
271
  rb_define_method(rb_cGrnType, "unsigned_integer?",
233
272
  rb_grn_type_unsigned_integer_p, 0);
234
273
  rb_define_alias(rb_cGrnType, "uint?", "unsigned_integer?");
@@ -238,6 +277,9 @@ rb_grn_init_type (VALUE mGrn)
238
277
 
239
278
  rb_define_method(rb_cGrnType, "float?", rb_grn_type_float_p, 0);
240
279
  rb_define_method(rb_cGrnType, "geo_point?", rb_grn_type_geo_point_p, 0);
280
+ rb_define_method(rb_cGrnType, "text_family?", rb_grn_type_text_family_p, 0);
281
+ rb_define_method(rb_cGrnType, "number_family?",
282
+ rb_grn_type_number_family_p, 0);
241
283
 
242
284
  /* 任意のテーブルに属する全てのレコード(Object型はv1.2で
243
285
  サポートされます)。 */
data/ext/groonga/rb-grn.h CHANGED
@@ -99,11 +99,7 @@ RB_GRN_BEGIN_DECLS
99
99
 
100
100
  #define RB_GRN_MAJOR_VERSION 6
101
101
  #define RB_GRN_MINOR_VERSION 0
102
- #define RB_GRN_MICRO_VERSION 0
103
-
104
- #define RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS 32
105
-
106
- #include <stdint.h>
102
+ #define RB_GRN_MICRO_VERSION 2
107
103
 
108
104
  #define RB_GRN_OBJECT(object) ((RbGrnObject *)(object))
109
105
  #define RB_GRN_NAMED_OBJECT(object) ((RbGrnNamedObject *)(object))
@@ -300,6 +296,9 @@ RB_GRN_VAR VALUE rb_cGrnColumnExpressionBuilder;
300
296
  RB_GRN_VAR VALUE rb_cGrnPlugin;
301
297
  RB_GRN_VAR VALUE rb_cGrnNormalizer;
302
298
  RB_GRN_VAR VALUE rb_cGrnIndex;
299
+ RB_GRN_VAR VALUE rb_mGrnRequestCanceler;
300
+ RB_GRN_VAR VALUE rb_mGrnRequestTimer;
301
+ RB_GRN_VAR VALUE rb_cGrnRequestTimerID;
303
302
 
304
303
  void rb_grn_init_utils (VALUE mGrn);
305
304
  void rb_grn_init_exception (VALUE mGrn);
@@ -355,6 +354,9 @@ void rb_grn_init_normalizer (VALUE mGrn);
355
354
  void rb_grn_init_thread (VALUE mGrn);
356
355
  void rb_grn_init_config (VALUE mGrn);
357
356
  void rb_grn_init_index (VALUE mGrn);
357
+ void rb_grn_init_request_canceler (VALUE mGrn);
358
+ void rb_grn_init_request_timer (VALUE mGrn);
359
+ void rb_grn_init_request_timer_id (VALUE mGrn);
358
360
 
359
361
  VALUE rb_grn_rc_to_exception (grn_rc rc);
360
362
  const char *rb_grn_rc_to_message (grn_rc rc);
@@ -738,6 +740,11 @@ VALUE rb_grn_index_new (VALUE rb_index_column,
738
740
  #define RVAL2GRNVARIABLE(object, context) \
739
741
  (rb_grn_variable_from_ruby_object(object, context))
740
742
 
743
+ #define GRN_REQUEST_TIMER_ID2RVAL(id) \
744
+ (rb_grn_request_timer_id_to_ruby_object(id))
745
+ #define RVAL2GRN_REQUEST_TIMER_ID(rb_id) \
746
+ (rb_grn_request_timer_id_from_ruby_object(rb_id))
747
+
741
748
 
742
749
  grn_encoding rb_grn_encoding_from_ruby_object (VALUE object,
743
750
  grn_ctx *context);
@@ -882,6 +889,11 @@ VALUE rb_grn_obj_to_ruby_object (VALUE klass,
882
889
  grn_obj *obj,
883
890
  VALUE related_object);
884
891
 
892
+ void *rb_grn_request_timer_id_from_ruby_object
893
+ (VALUE rb_id);
894
+ VALUE rb_grn_request_timer_id_to_ruby_object
895
+ (void *id);
896
+
885
897
  void rb_grn_snippet_bind (RbGrnSnippet *rb_grn_snippet,
886
898
  grn_ctx *context,
887
899
  grn_obj *snippet);
@@ -249,4 +249,7 @@ Init_groonga (void)
249
249
  rb_grn_init_thread(mGrn);
250
250
  rb_grn_init_config(mGrn);
251
251
  rb_grn_init_index(mGrn);
252
+ rb_grn_init_request_canceler(mGrn);
253
+ rb_grn_init_request_timer(mGrn);
254
+ rb_grn_init_request_timer_id(mGrn);
252
255
  }
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
4
2
  # Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
5
3
  #
@@ -77,23 +75,16 @@ module Groonga
77
75
  builders << match(@query, default_parse_options) if @query
78
76
  if block_given?
79
77
  custom_builder = yield(self)
80
- if custom_builder.is_a?(::Array)
81
- builders.concat(custom_builder)
82
- else
83
- builders << custom_builder
84
- end
78
+ builders << custom_builder
79
+ builders.flatten!
85
80
  end
86
81
 
87
82
  if builders.empty?
88
83
  expression.append_object(@table.context["all_records"])
89
84
  expression.append_operation(Operation::CALL, 0)
90
85
  else
91
- combined_builder = builders.inject(nil) do |previous, builder|
92
- if previous.nil?
93
- builder
94
- else
95
- previous & builder
96
- end
86
+ combined_builder = builders.inject do |previous, builder|
87
+ previous & builder
97
88
  end
98
89
  combined_builder.build(expression, variable)
99
90
  end
data/rroonga-build.rb CHANGED
@@ -20,15 +20,15 @@ module RroongaBuild
20
20
  module RequiredGroongaVersion
21
21
  MAJOR = 6
22
22
  MINOR = 0
23
- MICRO = 0
23
+ MICRO = 2
24
24
  VERSION = [MAJOR, MINOR, MICRO]
25
- RELEASED_DATE = Time.utc(2016, 2, 29)
25
+ RELEASED_DATE = Time.utc(2016, 4, 29)
26
26
  end
27
27
 
28
28
  module LatestGroongaVersion
29
29
  MAJOR = 6
30
30
  MINOR = 0
31
- MICRO = 0
31
+ MICRO = 2
32
32
  VERSION = [MAJOR, MINOR, MICRO]
33
33
  end
34
34
 
data/rroonga.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -86,7 +86,6 @@ Gem::Specification.new do |s|
86
86
  s.add_runtime_dependency("json")
87
87
  s.add_runtime_dependency("archive-zip")
88
88
  s.add_development_dependency("test-unit", [">= 3.0.0"])
89
- s.add_development_dependency("test-unit-notify")
90
89
  s.add_development_dependency("rake")
91
90
  s.add_development_dependency("rake-compiler", [">= 0.9.5"])
92
91
  s.add_development_dependency("rake-compiler-dock")
data/test/run-test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009-2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -37,7 +37,7 @@ if make
37
37
  end
38
38
 
39
39
  require "test-unit"
40
- require "test/unit/notify"
40
+ require "test/unit/priority"
41
41
 
42
42
  Test::Unit::Priority.enable
43
43