rroonga 5.0.1 → 5.0.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: f9abb0782118ae8bf3bc7ae7fd91b2947d23568f
4
- data.tar.gz: d4cd06feff63ea165f725fcc667de0d6e35d7ed3
3
+ metadata.gz: 0a3d4a6d287300f6e5850b233cdcfb23f8cb83a7
4
+ data.tar.gz: d33d0d1174dca89402649b2493f25f98db74098f
5
5
  SHA512:
6
- metadata.gz: a537e4dab40a080c59a801492b55b0aa103734cd3103ae616dceecdde3fd9fdd8b7ef400c67962854dfe4cba8685ef4ea24431e0eade2b7df7eb8360d57ea840
7
- data.tar.gz: 2cf053bf2f30202391d013839f394d344280ef5666abac6d75cb4564043977b965f55a8320bd29cda9cccdf19eec0f96c34edb35c870121322f080bf6aacefb5
6
+ metadata.gz: 0743960c36734c384b7918b8a43c5e76be58e7ac6a3872240ecb7ec81a357ddb27289e8129c15d6aebe635e823c98d1901cd4fdff14d0b7d0272bbc2a9f60c24
7
+ data.tar.gz: c202e713749c0c39b4ee80b3afc1b49ee4e01d8464f4a56fdb1a5fa0727893a893f0660c85a038640a9a88fee9dd480e2b4ae5a253965ae8cd83143aeebfbc62
data/README.md CHANGED
@@ -40,7 +40,7 @@ contributed patches.)
40
40
  ## Dependencies
41
41
 
42
42
  * Ruby >= 1.9.3
43
- * Groonga >= 5.0.0
43
+ * Groonga >= 5.0.2
44
44
 
45
45
  ## Install
46
46
 
data/Rakefile CHANGED
@@ -19,8 +19,6 @@ require "find"
19
19
  require "fileutils"
20
20
  require "pathname"
21
21
  require "erb"
22
- require "rubygems"
23
- require "rubygems/package_task"
24
22
  require "yard"
25
23
  require "bundler/gem_helper"
26
24
  require "rake/extensiontask"
@@ -42,10 +40,6 @@ end
42
40
  helper.install
43
41
  spec = helper.gemspec
44
42
 
45
- Gem::PackageTask.new(spec) do |pkg|
46
- pkg.need_tar_gz = true
47
- end
48
-
49
43
  Packnga::DocumentTask.new(spec) do |task|
50
44
  task.original_language = "en"
51
45
  task.translate_language = "ja"
data/example/bookmark.rb CHANGED
@@ -7,12 +7,7 @@ groonga_lib_dir = File.join(base_dir, "lib")
7
7
  $LOAD_PATH.unshift(groonga_ext_dir)
8
8
  $LOAD_PATH.unshift(groonga_lib_dir)
9
9
 
10
- begin
11
- require "groonga"
12
- rescue LoadError
13
- require "rubygems"
14
- require "groonga"
15
- end
10
+ require "groonga"
16
11
 
17
12
  require "time"
18
13
 
@@ -11,7 +11,6 @@ base_directory = Pathname(__FILE__).dirname + ".."
11
11
  $LOAD_PATH.unshift((base_directory + "ext").to_s)
12
12
  $LOAD_PATH.unshift((base_directory + "lib").to_s)
13
13
 
14
- require "rubygems"
15
14
  require "groonga"
16
15
  require "nokogiri"
17
16
 
@@ -95,12 +95,7 @@ def download(url)
95
95
  end
96
96
 
97
97
  def extract_zip(filename, destrination_dir)
98
- begin
99
- require "archive/zip"
100
- rescue LoadError
101
- require "rubygems"
102
- require "archive/zip"
103
- end
98
+ require "archive/zip"
104
99
 
105
100
  Archive::Zip.extract(filename, destrination_dir)
106
101
  rescue LoadError
@@ -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-2013 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2015 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
@@ -32,6 +32,11 @@ VALUE cGrnLogger;
32
32
  VALUE mGrnLoggerFlags;
33
33
  VALUE cGrnCallbackLogger;
34
34
 
35
+ static ID id_caller_locations;
36
+ static ID id_path;
37
+ static ID id_lineno;
38
+ static ID id_label;
39
+
35
40
  static ID id_new;
36
41
  static ID id_parse;
37
42
  static ID id_log;
@@ -122,6 +127,96 @@ rb_grn_log_level_to_ruby_object (grn_log_level level)
122
127
  return rb_level;
123
128
  }
124
129
 
130
+ /*
131
+ * Logs a message.
132
+ *
133
+ * @overload log(message, options={})
134
+ * @param message [String] The log message.
135
+ * @param options [::Hash]
136
+ * @option options :context [Groonga::Context] (Groonga::Context.default)
137
+ * The context for the message.
138
+ * @option options :level [nil, :none, :emergency, :alert, :critical,
139
+ * :error, :warning, :notice, :info, :debug, :dump] (:notice)
140
+ * The level for the message.
141
+ *
142
+ * `nil` equals to `:notice`.
143
+ * @option options :file [nil, String] (nil)
144
+ * The file name where the message is occurred.
145
+ *
146
+ * If all of `:file`, `:line` and `:function` are nil, these
147
+ * values are guessed from `Kernel.#caller_locations` result.
148
+ * @option options :line [nil, Integer] (nil)
149
+ * The line number where the message is occurred.
150
+ * @option options :function [nil, String] (nil)
151
+ * The function or related name such as method name where the
152
+ * message is occurred.
153
+ * @return [void]
154
+ *
155
+ * @since 5.0.2
156
+ */
157
+ static VALUE
158
+ rb_grn_logger_s_log (int argc, VALUE *argv, VALUE klass)
159
+ {
160
+ VALUE rb_message;
161
+ const char *message;
162
+ VALUE rb_context = Qnil;
163
+ grn_ctx *context;
164
+ VALUE rb_level;
165
+ grn_log_level level = GRN_LOG_DEFAULT_LEVEL;
166
+ VALUE rb_file;
167
+ const char *file = NULL;
168
+ VALUE rb_line;
169
+ int line;
170
+ VALUE rb_function;
171
+ const char *function = NULL;
172
+ VALUE rb_options;
173
+
174
+ rb_scan_args(argc, argv, "11", &rb_message, &rb_options);
175
+
176
+ message = StringValueCStr(rb_message);
177
+
178
+ rb_grn_scan_options(rb_options,
179
+ "context", &rb_context,
180
+ "level", &rb_level,
181
+ "file", &rb_file,
182
+ "line", &rb_line,
183
+ "function", &rb_function,
184
+ NULL);
185
+
186
+ context = rb_grn_context_ensure(&rb_context);
187
+
188
+ if (!NIL_P(rb_level)) {
189
+ level = RVAL2GRNLOGLEVEL(rb_level);
190
+ }
191
+
192
+ if (NIL_P(rb_file) && NIL_P(rb_line) && NIL_P(rb_function)) {
193
+ VALUE rb_locations;
194
+ VALUE rb_location;
195
+ rb_locations = rb_funcall(rb_cObject,
196
+ id_caller_locations,
197
+ 2,
198
+ INT2NUM(1), INT2NUM(1));
199
+ rb_location = RARRAY_PTR(rb_locations)[0];
200
+ rb_file = rb_funcall(rb_location, id_path, 0);
201
+ rb_line = rb_funcall(rb_location, id_lineno, 0);
202
+ rb_function = rb_funcall(rb_location, id_label, 0);
203
+ }
204
+
205
+ if (!NIL_P(rb_file)) {
206
+ file = StringValueCStr(rb_file);
207
+ }
208
+ if (!NIL_P(rb_line)) {
209
+ line = NUM2INT(rb_line);
210
+ }
211
+ if (!NIL_P(rb_function)) {
212
+ function = StringValueCStr(rb_function);
213
+ }
214
+
215
+ grn_logger_put(context, level, file, line, function, "%s", message);
216
+
217
+ return Qnil;
218
+ }
219
+
125
220
  static void
126
221
  rb_grn_logger_reset_with_error_check (VALUE klass, grn_ctx *context)
127
222
  {
@@ -344,7 +439,7 @@ rb_grn_logger_s_reopen (VALUE klass)
344
439
  }
345
440
 
346
441
  /*
347
- * Gets the current log path that is used the default logger.
442
+ * Gets the current log path that is used by the default logger.
348
443
  *
349
444
  * @overload path
350
445
  * @return [String or nil] The current log path
@@ -365,7 +460,7 @@ rb_grn_logger_s_get_path (VALUE klass)
365
460
  }
366
461
 
367
462
  /*
368
- * Sets the log path that is used the default logger. If you're using
463
+ * Sets the log path that is used by the default logger. If you're using
369
464
  * custom logger by {.register}, the log path isn't used. Because it
370
465
  * is for the default logger.
371
466
  *
@@ -411,9 +506,64 @@ rb_grn_logger_s_set_path (VALUE klass, VALUE rb_path)
411
506
  return Qnil;
412
507
  }
413
508
 
509
+ /*
510
+ * Gets the current rotate threshold size that is used by the default
511
+ * logger.
512
+ *
513
+ * If the size is larger than 0, log rotate feature is enabled in the
514
+ * default logger.
515
+ *
516
+ * @overload threshold
517
+ * @return [Integer] The current rotate threshold size
518
+ *
519
+ * @since 5.0.2
520
+ */
521
+ static VALUE
522
+ rb_grn_logger_s_get_rotate_threshold_size (VALUE klass)
523
+ {
524
+ return OFFT2NUM(grn_default_logger_get_rotate_threshold_size());
525
+ }
526
+
527
+ /*
528
+ * Sets the rotate threshold size that is used by the default
529
+ * logger. If you're using custom logger by {.register}, the rotate
530
+ * threshold size isn't used. Because it is for the default logger.
531
+ *
532
+ * If you specify `0` as size, log rotation by the default logger is
533
+ * disabled.
534
+ *
535
+ * The default rotate threshold size is 0. It means that log rotation
536
+ * is disabled by default.
537
+ *
538
+ * @example Changes the rotate threshold size for the default logger
539
+ * Groonga::Logger.rotate_threshold_size = 1 * 1024 * 1024 # 1MiB
540
+ *
541
+ * @example Disables log ration by the default logger
542
+ * Groonga::Logger.rotate_threshold_size = 0
543
+ *
544
+ * @overload rotate_threshold_size=(size)
545
+ * @param size [Integer] The log path for the default logger.
546
+ * If nil is specified, log rotate by the default logger is disabled.
547
+ * @return void
548
+ *
549
+ * @since 5.0.2
550
+ */
551
+ static VALUE
552
+ rb_grn_logger_s_set_rotate_threshold_size (VALUE klass, VALUE rb_size)
553
+ {
554
+ grn_default_logger_set_rotate_threshold_size(NUM2OFFT(rb_size));
555
+
556
+ return Qnil;
557
+ }
558
+
414
559
  void
415
560
  rb_grn_init_logger (VALUE mGrn)
416
561
  {
562
+ id_caller_locations = rb_intern("caller_locations");
563
+ id_path = rb_intern("path");
564
+ id_lineno = rb_intern("lineno");
565
+ id_label = rb_intern("label");
566
+
417
567
  id_new = rb_intern("new");
418
568
  id_parse = rb_intern("parse");
419
569
  id_log = rb_intern("log");
@@ -429,6 +579,8 @@ rb_grn_init_logger (VALUE mGrn)
429
579
  cGrnLogger = rb_define_class_under(mGrn, "Logger", rb_cObject);
430
580
 
431
581
  rb_cv_set(cGrnLogger, "@@current_logger", Qnil);
582
+ rb_define_singleton_method(cGrnLogger, "log",
583
+ rb_grn_logger_s_log, -1);
432
584
  rb_define_singleton_method(cGrnLogger, "register",
433
585
  rb_grn_logger_s_register, -1);
434
586
  rb_define_singleton_method(cGrnLogger, "unregister",
@@ -439,6 +591,10 @@ rb_grn_init_logger (VALUE mGrn)
439
591
  rb_grn_logger_s_get_path, 0);
440
592
  rb_define_singleton_method(cGrnLogger, "path=",
441
593
  rb_grn_logger_s_set_path, 1);
594
+ rb_define_singleton_method(cGrnLogger, "rotate_threshold_size",
595
+ rb_grn_logger_s_get_rotate_threshold_size, 0);
596
+ rb_define_singleton_method(cGrnLogger, "rotate_threshold_size=",
597
+ rb_grn_logger_s_set_rotate_threshold_size, 1);
442
598
  rb_set_end_proc(rb_grn_logger_reset, cGrnLogger);
443
599
 
444
600
  mGrnLoggerFlags = rb_define_module_under(cGrnLogger, "Flags");
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2011-2015 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
@@ -191,6 +191,20 @@ rb_grn_plugin_s_suffix (VALUE klass)
191
191
  return rb_str_new_cstr(grn_plugin_get_suffix());
192
192
  }
193
193
 
194
+ /*
195
+ * Returns the plugin file suffix written in Ruby. It returns ".rb".
196
+ *
197
+ * @overload ruby_suffix
198
+ * @return [String]
199
+ *
200
+ * @since 5.0.2
201
+ */
202
+ static VALUE
203
+ rb_grn_plugin_s_ruby_suffix (VALUE klass)
204
+ {
205
+ return rb_str_new_cstr(grn_plugin_get_ruby_suffix());
206
+ }
207
+
194
208
  void
195
209
  rb_grn_init_plugin (VALUE mGrn)
196
210
  {
@@ -205,4 +219,6 @@ rb_grn_init_plugin (VALUE mGrn)
205
219
  rb_grn_plugin_s_system_plugins_dir, 0);
206
220
  rb_define_singleton_method(cGrnPlugin, "suffix",
207
221
  rb_grn_plugin_s_suffix, 0);
222
+ rb_define_singleton_method(cGrnPlugin, "ruby_suffix",
223
+ rb_grn_plugin_s_ruby_suffix, 0);
208
224
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2012-2015 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
@@ -45,6 +45,72 @@ rb_grn_query_log_flags_to_ruby_object (unsigned int flags)
45
45
  return UINT2NUM(flags);
46
46
  }
47
47
 
48
+ /*
49
+ * Logs a message.
50
+ *
51
+ * @overload log(message, options={})
52
+ * @param message [String] The log message.
53
+ * @param options [::Hash]
54
+ * @option options :context [Groonga::Context] (Groonga::Context.default)
55
+ * The context for the message.
56
+ * @option options :flags [nil, Integer, String] (0)
57
+ * The flags for the message.
58
+ *
59
+ * The flags are passed to query logger. You can custom query
60
+ * logger behavior by the flags. For example, you can omit elapsed
61
+ * time by passing `Groonga::QueryLogger::COMMAND` flag or
62
+ * `Groonga::QueryLogger::DESTINATION`.
63
+ *
64
+ * If `:flags` value is `String`, parsed by
65
+ * {Groonga::QueryLogger.parse}.
66
+ *
67
+ * `nil` equals to `0`.
68
+ * @option options :mark [String] ("")
69
+ * The mark for the message.
70
+ *
71
+ * Normally, a character is used as a mark such as `":"`, `"<"` and `">"`.
72
+ * @return [void]
73
+ *
74
+ * @since 5.0.2
75
+ */
76
+ static VALUE
77
+ rb_grn_query_logger_s_log (int argc, VALUE *argv, VALUE klass)
78
+ {
79
+ VALUE rb_message;
80
+ const char *message;
81
+ VALUE rb_context = Qnil;
82
+ grn_ctx *context;
83
+ VALUE rb_flags;
84
+ unsigned int flags = GRN_QUERY_LOG_NONE;
85
+ VALUE rb_mark;
86
+ const char *mark = "";
87
+ VALUE rb_options;
88
+
89
+ rb_scan_args(argc, argv, "11", &rb_message, &rb_options);
90
+
91
+ message = StringValueCStr(rb_message);
92
+
93
+ rb_grn_scan_options(rb_options,
94
+ "context", &rb_context,
95
+ "flags", &rb_flags,
96
+ "mark", &rb_mark,
97
+ NULL);
98
+
99
+ context = rb_grn_context_ensure(&rb_context);
100
+
101
+ if (!NIL_P(rb_flags)) {
102
+ flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 2,
103
+ rb_flags, UINT2NUM(flags));
104
+ }
105
+ if (!NIL_P(rb_mark)) {
106
+ mark = StringValueCStr(rb_mark);
107
+ }
108
+
109
+ grn_query_logger_put(context, flags, mark, "%s", message);
110
+
111
+ return Qnil;
112
+ }
113
+
48
114
  static void
49
115
  rb_grn_query_logger_log (grn_ctx *ctx, unsigned int flag,
50
116
  const char *timestamp, const char *info,
@@ -100,7 +166,7 @@ rb_grn_query_logger_fin (grn_ctx *ctx, void *user_data)
100
166
  * @option options [Symbol, String, Integer or nil] :flags (:default)
101
167
  * Flags describe what query log should be logged.
102
168
  *
103
- * If @flags@ is String, it is parsed by {QueryLogger::Flags.parse}.
169
+ * If `flags` is String, it is parsed by {QueryLogger::Flags.parse}.
104
170
  *
105
171
  * @return void
106
172
  *
@@ -164,7 +230,7 @@ rb_grn_query_logger_s_register (int argc, VALUE *argv, VALUE klass)
164
230
  }
165
231
  if (!NIL_P(rb_flags)) {
166
232
  flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 2,
167
- UINT2NUM(flags), rb_flags);
233
+ rb_flags, UINT2NUM(flags));
168
234
  }
169
235
 
170
236
  rb_grn_query_logger.flags = flags;
@@ -287,6 +353,58 @@ rb_grn_query_logger_s_set_path (VALUE klass, VALUE rb_path)
287
353
  return Qnil;
288
354
  }
289
355
 
356
+ /*
357
+ * Gets the current rotate threshold size that is used by the default
358
+ * query logger.
359
+ *
360
+ * If the size is larger than 0, log rotate feature is enabled in the
361
+ * default query logger.
362
+ *
363
+ * @overload threshold
364
+ * @return [Integer] The current rotate threshold size
365
+ *
366
+ * @since 5.0.2
367
+ */
368
+ static VALUE
369
+ rb_grn_query_logger_s_get_rotate_threshold_size (VALUE klass)
370
+ {
371
+ return OFFT2NUM(grn_default_query_logger_get_rotate_threshold_size());
372
+ }
373
+
374
+ /*
375
+ * Sets the rotate threshold size that is used by the default query
376
+ * logger. If you're using custom query logger by {.register}, the
377
+ * rotate threshold size isn't used. Because it is for the default
378
+ * query logger.
379
+ *
380
+ * If you specify `0` as size, log rotation by the default query
381
+ * logger is disabled.
382
+ *
383
+ * The default rotate threshold size is 0. It means that log rotation
384
+ * is disabled by default.
385
+ *
386
+ * @example Changes the rotate threshold size for the default query logger
387
+ * Groonga::QueryLogger.rotate_threshold_size = 1 * 1024 * 1024 # 1MiB
388
+ *
389
+ * @example Disables log ration by the default query logger
390
+ * Groonga::QueryLogger.rotate_threshold_size = 0
391
+ *
392
+ * @overload rotate_threshold_size=(size)
393
+ * @param size [Integer] The log path for the default query logger.
394
+ * If nil is specified, log rotate by the default query logger is
395
+ * disabled.
396
+ * @return void
397
+ *
398
+ * @since 5.0.2
399
+ */
400
+ static VALUE
401
+ rb_grn_query_logger_s_set_rotate_threshold_size (VALUE klass, VALUE rb_size)
402
+ {
403
+ grn_default_query_logger_set_rotate_threshold_size(NUM2OFFT(rb_size));
404
+
405
+ return Qnil;
406
+ }
407
+
290
408
  void
291
409
  rb_grn_init_query_logger (VALUE mGrn)
292
410
  {
@@ -305,6 +423,8 @@ rb_grn_init_query_logger (VALUE mGrn)
305
423
  cGrnQueryLogger = rb_define_class_under(mGrn, "QueryLogger", rb_cObject);
306
424
 
307
425
  rb_cv_set(cGrnQueryLogger, "@@current_logger", Qnil);
426
+ rb_define_singleton_method(cGrnQueryLogger, "log",
427
+ rb_grn_query_logger_s_log, -1);
308
428
  rb_define_singleton_method(cGrnQueryLogger, "register",
309
429
  rb_grn_query_logger_s_register, -1);
310
430
  rb_define_singleton_method(cGrnQueryLogger, "unregister",
@@ -315,6 +435,12 @@ rb_grn_init_query_logger (VALUE mGrn)
315
435
  rb_grn_query_logger_s_get_path, 0);
316
436
  rb_define_singleton_method(cGrnQueryLogger, "path=",
317
437
  rb_grn_query_logger_s_set_path, 1);
438
+ rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size",
439
+ rb_grn_query_logger_s_get_rotate_threshold_size,
440
+ 0);
441
+ rb_define_singleton_method(cGrnQueryLogger, "rotate_threshold_size=",
442
+ rb_grn_query_logger_s_set_rotate_threshold_size,
443
+ 1);
318
444
 
319
445
  mGrnQueryLoggerFlags = rb_define_module_under(cGrnQueryLogger, "Flags");
320
446
  #define DEFINE_FLAG(NAME) \