rgeoip 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/ext/rgeoip.c +189 -15
- data/rgeoip.gemspec +12 -4
- data/test/test_rgeoip.rb +42 -2
- data/test/test_rgeoip_database.rb +62 -0
- metadata +21 -53
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/ext/rgeoip.c
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
3
|
+
#include "ruby/encoding.h"
|
4
|
+
#endif
|
2
5
|
#include <GeoIP.h>
|
3
6
|
#include <GeoIPCity.h>
|
4
7
|
|
@@ -27,11 +30,19 @@ enum {
|
|
27
30
|
|
28
31
|
static VALUE rb_cRgeoip, rb_cRgeoipDatabase;
|
29
32
|
static VALUE rgeoip_symbols[RGEOIP_SYMBOLS_MAX];
|
33
|
+
static ID i_to_s;
|
34
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
35
|
+
static rb_encoding *enc_utf8;
|
36
|
+
static rb_encoding *enc_iso_8859_1;
|
37
|
+
#endif
|
30
38
|
|
31
39
|
/* -------- */
|
32
40
|
|
33
41
|
typedef struct {
|
34
|
-
VALUE
|
42
|
+
VALUE databases;
|
43
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
44
|
+
rb_encoding *encoding;
|
45
|
+
#endif
|
35
46
|
} Rgeoip;
|
36
47
|
|
37
48
|
typedef struct {
|
@@ -54,6 +65,12 @@ static VALUE
|
|
54
65
|
gi_country(VALUE self, VALUE addr_or_host);
|
55
66
|
static VALUE
|
56
67
|
gi_city(VALUE self, VALUE addr_or_host);
|
68
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
69
|
+
static VALUE
|
70
|
+
gi_set_encoding(VALUE, VALUE);
|
71
|
+
static VALUE
|
72
|
+
gi_get_encoding(VALUE);
|
73
|
+
#endif
|
57
74
|
static VALUE
|
58
75
|
gid_alloc(VALUE klass);
|
59
76
|
static void
|
@@ -64,6 +81,14 @@ static VALUE
|
|
64
81
|
gid_country(VALUE self, VALUE addr_or_host);
|
65
82
|
static VALUE
|
66
83
|
gid_city(VALUE self, VALUE addr_or_host);
|
84
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
85
|
+
static VALUE
|
86
|
+
gid_set_encoding(VALUE, VALUE);
|
87
|
+
static VALUE
|
88
|
+
gid_get_encoding(VALUE);
|
89
|
+
#endif
|
90
|
+
static VALUE
|
91
|
+
gid_enc_str(RgeoipDatabase *, const char*);
|
67
92
|
static GeoIP_id_by
|
68
93
|
GeoIP_id_dwim(VALUE addr);
|
69
94
|
static GeoIP_record_by
|
@@ -72,6 +97,10 @@ static int
|
|
72
97
|
is_addr_p(VALUE value);
|
73
98
|
static VALUE
|
74
99
|
rb_hash_sset(VALUE hash, VALUE key, VALUE value);
|
100
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
101
|
+
static rb_encoding*
|
102
|
+
charset2encoding(GeoIPCharset charset);
|
103
|
+
#endif
|
75
104
|
|
76
105
|
/* Rgeoip */
|
77
106
|
/*
|
@@ -124,6 +153,9 @@ gi_new(int argc, VALUE *argv, VALUE self)
|
|
124
153
|
}
|
125
154
|
|
126
155
|
gi->databases = rb_ary_new();
|
156
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
157
|
+
gi->encoding = enc_iso_8859_1;
|
158
|
+
#endif
|
127
159
|
|
128
160
|
for (i=0; i<argc; i++)
|
129
161
|
{
|
@@ -154,7 +186,7 @@ static VALUE
|
|
154
186
|
gi_open(VALUE self, VALUE filenames)
|
155
187
|
{
|
156
188
|
Rgeoip *gi;
|
157
|
-
VALUE args[
|
189
|
+
VALUE args[3] = {0};
|
158
190
|
Data_Get_Struct(self, Rgeoip, gi);
|
159
191
|
|
160
192
|
if (TYPE(filenames) == T_ARRAY)
|
@@ -164,7 +196,11 @@ gi_open(VALUE self, VALUE filenames)
|
|
164
196
|
else
|
165
197
|
{
|
166
198
|
args[0] = filenames;
|
167
|
-
|
199
|
+
args[1] = Qnil;
|
200
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
201
|
+
args[2] = gi_get_encoding(self);
|
202
|
+
#endif
|
203
|
+
rb_ary_push(gi->databases, rb_class_new_instance(3, args, rb_cRgeoipDatabase));
|
168
204
|
}
|
169
205
|
|
170
206
|
return self;
|
@@ -243,6 +279,39 @@ gi_city(VALUE self, VALUE addr_or_host)
|
|
243
279
|
return Qnil;
|
244
280
|
}
|
245
281
|
|
282
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
283
|
+
static VALUE
|
284
|
+
gi_set_encoding(VALUE self, VALUE enc)
|
285
|
+
{
|
286
|
+
Rgeoip *gi;
|
287
|
+
rb_encoding *rb_enc;
|
288
|
+
Data_Get_Struct(self, Rgeoip, gi);
|
289
|
+
|
290
|
+
rb_enc = rb_to_encoding(enc);
|
291
|
+
if (strcmp((rb_enc_name(rb_enc)), "UTF-8") == 0 ||
|
292
|
+
strcmp((rb_enc_name(rb_enc)), "ISO-8859-1") == 0)
|
293
|
+
{
|
294
|
+
gi->encoding = rb_enc;
|
295
|
+
}
|
296
|
+
else
|
297
|
+
{
|
298
|
+
rb_raise(rb_eRuntimeError, "Unsupported Encoding");
|
299
|
+
}
|
300
|
+
return gi_get_encoding(self);
|
301
|
+
}
|
302
|
+
#endif
|
303
|
+
|
304
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
305
|
+
static VALUE
|
306
|
+
gi_get_encoding(VALUE self)
|
307
|
+
{
|
308
|
+
Rgeoip *gi;
|
309
|
+
Data_Get_Struct(self, Rgeoip, gi);
|
310
|
+
|
311
|
+
return rb_enc_from_encoding(gi->encoding);
|
312
|
+
}
|
313
|
+
#endif
|
314
|
+
|
246
315
|
/* Rgeoip::Database */
|
247
316
|
/*
|
248
317
|
* Document-class: Rgeoip::Database
|
@@ -280,7 +349,7 @@ static VALUE
|
|
280
349
|
gid_new(int argc, VALUE *argv, VALUE self)
|
281
350
|
{
|
282
351
|
RgeoipDatabase *gid;
|
283
|
-
VALUE filename, flags;
|
352
|
+
VALUE filename, flags, encoding;
|
284
353
|
|
285
354
|
Data_Get_Struct(self, RgeoipDatabase, gid);
|
286
355
|
if (gid == NULL)
|
@@ -290,9 +359,9 @@ gid_new(int argc, VALUE *argv, VALUE self)
|
|
290
359
|
DATA_PTR(self) = gid;
|
291
360
|
}
|
292
361
|
|
293
|
-
rb_scan_args(argc, argv, "
|
362
|
+
rb_scan_args(argc, argv, "12", &filename, &flags, &encoding);
|
294
363
|
|
295
|
-
filename =
|
364
|
+
filename = rb_funcall(filename, i_to_s, 0);
|
296
365
|
|
297
366
|
gid->ptr = GeoIP_open(RSTRING_PTR(filename),
|
298
367
|
GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE | GEOIP_MMAP_CACHE);
|
@@ -301,6 +370,14 @@ gid_new(int argc, VALUE *argv, VALUE self)
|
|
301
370
|
rb_raise(rb_eRuntimeError, "Problem opening database");
|
302
371
|
}
|
303
372
|
|
373
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
374
|
+
if (NIL_P(encoding))
|
375
|
+
{
|
376
|
+
encoding = rb_str_new2("ISO-8859-1");
|
377
|
+
}
|
378
|
+
gid_set_encoding(self, encoding);
|
379
|
+
#endif
|
380
|
+
|
304
381
|
return self;
|
305
382
|
}
|
306
383
|
|
@@ -337,15 +414,15 @@ gid_country(VALUE self, VALUE addr_or_host)
|
|
337
414
|
result = rb_hash_new();
|
338
415
|
if (GeoIP_code_by_id(id))
|
339
416
|
{
|
340
|
-
rb_hash_sset(result, rgeoip_symbols[RS_CODE],
|
417
|
+
rb_hash_sset(result, rgeoip_symbols[RS_CODE], gid_enc_str(gid, GeoIP_code_by_id(id)));
|
341
418
|
}
|
342
419
|
if (GeoIP_code3_by_id(id))
|
343
420
|
{
|
344
|
-
rb_hash_sset(result, rgeoip_symbols[RS_CODE3],
|
421
|
+
rb_hash_sset(result, rgeoip_symbols[RS_CODE3], gid_enc_str(gid, GeoIP_code3_by_id(id)));
|
345
422
|
}
|
346
423
|
if (GeoIP_name_by_id(id))
|
347
424
|
{
|
348
|
-
rb_hash_sset(result, rgeoip_symbols[RS_NAME],
|
425
|
+
rb_hash_sset(result, rgeoip_symbols[RS_NAME], gid_enc_str(gid, GeoIP_name_by_id(id)));
|
349
426
|
}
|
350
427
|
|
351
428
|
return result;
|
@@ -384,27 +461,27 @@ gid_city(VALUE self, VALUE addr_or_host)
|
|
384
461
|
result = rb_hash_new();
|
385
462
|
if (record->country_code)
|
386
463
|
{
|
387
|
-
rb_hash_sset(result, rgeoip_symbols[RS_CODE],
|
464
|
+
rb_hash_sset(result, rgeoip_symbols[RS_CODE], gid_enc_str(gid, record->country_code));
|
388
465
|
}
|
389
466
|
if (record->country_code3)
|
390
467
|
{
|
391
|
-
rb_hash_sset(result, rgeoip_symbols[RS_CODE3],
|
468
|
+
rb_hash_sset(result, rgeoip_symbols[RS_CODE3], gid_enc_str(gid, record->country_code3));
|
392
469
|
}
|
393
470
|
if (record->country_name)
|
394
471
|
{
|
395
|
-
rb_hash_sset(result, rgeoip_symbols[RS_NAME],
|
472
|
+
rb_hash_sset(result, rgeoip_symbols[RS_NAME], gid_enc_str(gid, record->country_name));
|
396
473
|
}
|
397
474
|
if (record->region)
|
398
475
|
{
|
399
|
-
rb_hash_sset(result, rgeoip_symbols[RS_REGION],
|
476
|
+
rb_hash_sset(result, rgeoip_symbols[RS_REGION], gid_enc_str(gid, record->region));
|
400
477
|
}
|
401
478
|
if (record->city)
|
402
479
|
{
|
403
|
-
rb_hash_sset(result, rgeoip_symbols[RS_CITY],
|
480
|
+
rb_hash_sset(result, rgeoip_symbols[RS_CITY], gid_enc_str(gid, record->city));
|
404
481
|
}
|
405
482
|
if (record->postal_code)
|
406
483
|
{
|
407
|
-
rb_hash_sset(result, rgeoip_symbols[RS_POSTAL_CODE],
|
484
|
+
rb_hash_sset(result, rgeoip_symbols[RS_POSTAL_CODE], gid_enc_str(gid, record->postal_code));
|
408
485
|
}
|
409
486
|
rb_hash_sset(result, rgeoip_symbols[RS_LATITUDE], rb_float_new((double)record->latitude));
|
410
487
|
rb_hash_sset(result, rgeoip_symbols[RS_LONGITUDE], rb_float_new((double)record->longitude));
|
@@ -415,6 +492,69 @@ gid_city(VALUE self, VALUE addr_or_host)
|
|
415
492
|
return result;
|
416
493
|
}
|
417
494
|
|
495
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
496
|
+
static VALUE
|
497
|
+
gid_set_encoding(VALUE self, VALUE enc)
|
498
|
+
{
|
499
|
+
RgeoipDatabase *gid;
|
500
|
+
rb_encoding *rb_enc;
|
501
|
+
Data_Get_Struct(self, RgeoipDatabase, gid);
|
502
|
+
|
503
|
+
rb_enc = rb_to_encoding(enc);
|
504
|
+
if (strcmp(rb_enc_name(rb_enc), "ISO-8859-1") == 0)
|
505
|
+
{
|
506
|
+
GeoIP_set_charset(gid->ptr, GEOIP_CHARSET_ISO_8859_1);
|
507
|
+
}
|
508
|
+
else if (strcmp(rb_enc_name(rb_enc), "UTF-8") == 0)
|
509
|
+
{
|
510
|
+
GeoIP_set_charset(gid->ptr, GEOIP_CHARSET_UTF8);
|
511
|
+
}
|
512
|
+
else
|
513
|
+
{
|
514
|
+
rb_raise(rb_eRuntimeError, "Unsupported Encoding");
|
515
|
+
}
|
516
|
+
return gid_get_encoding(self);
|
517
|
+
}
|
518
|
+
#endif
|
519
|
+
|
520
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
521
|
+
static VALUE
|
522
|
+
gid_get_encoding(VALUE self)
|
523
|
+
{
|
524
|
+
RgeoipDatabase *gid;
|
525
|
+
rb_encoding *encoding;
|
526
|
+
Data_Get_Struct(self, RgeoipDatabase, gid);
|
527
|
+
|
528
|
+
encoding = charset2encoding(GeoIP_charset(gid->ptr));
|
529
|
+
if (encoding == NULL)
|
530
|
+
{
|
531
|
+
rb_raise(rb_eRuntimeError, "Unknown charset");
|
532
|
+
}
|
533
|
+
|
534
|
+
return rb_enc_from_encoding(encoding);
|
535
|
+
}
|
536
|
+
#endif
|
537
|
+
|
538
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
539
|
+
static VALUE
|
540
|
+
gid_enc_str(RgeoipDatabase *gid, const char* str)
|
541
|
+
{
|
542
|
+
rb_encoding *internal_encoding = rb_default_internal_encoding();
|
543
|
+
VALUE val = rb_enc_str_new(str, strlen(str),
|
544
|
+
charset2encoding(GeoIP_charset(gid->ptr)));
|
545
|
+
if (internal_encoding) {
|
546
|
+
val = rb_str_export_to_enc(val, internal_encoding);
|
547
|
+
}
|
548
|
+
return rb_str_freeze(val);
|
549
|
+
}
|
550
|
+
#else
|
551
|
+
static VALUE
|
552
|
+
gid_enc_str(RgeoipDatabase *gid, const char* str)
|
553
|
+
{
|
554
|
+
return rb_str_freeze(rb_str_new2(str));
|
555
|
+
}
|
556
|
+
#endif
|
557
|
+
|
418
558
|
/* -------- */
|
419
559
|
|
420
560
|
static GeoIP_id_by
|
@@ -465,6 +605,25 @@ rb_hash_sset(VALUE hash, VALUE key, VALUE value)
|
|
465
605
|
return rb_hash_aset(hash, key, value);
|
466
606
|
}
|
467
607
|
|
608
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
609
|
+
static rb_encoding*
|
610
|
+
charset2encoding(GeoIPCharset charset)
|
611
|
+
{
|
612
|
+
if (charset == GEOIP_CHARSET_ISO_8859_1)
|
613
|
+
{
|
614
|
+
return enc_iso_8859_1;
|
615
|
+
}
|
616
|
+
else if (charset == GEOIP_CHARSET_UTF8)
|
617
|
+
{
|
618
|
+
return enc_utf8;
|
619
|
+
}
|
620
|
+
else
|
621
|
+
{
|
622
|
+
return NULL;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
#endif
|
626
|
+
|
468
627
|
/* -------- */
|
469
628
|
|
470
629
|
void
|
@@ -476,12 +635,20 @@ Init_rgeoip(void)
|
|
476
635
|
rb_define_method(rb_cRgeoip, "open", gi_open, 1);
|
477
636
|
rb_define_method(rb_cRgeoip, "country", gi_country, 1);
|
478
637
|
rb_define_method(rb_cRgeoip, "city", gi_city, 1);
|
638
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
639
|
+
rb_define_method(rb_cRgeoip, "encoding=", gi_set_encoding, 1);
|
640
|
+
rb_define_method(rb_cRgeoip, "encoding", gi_get_encoding, 0);
|
641
|
+
#endif
|
479
642
|
|
480
643
|
rb_cRgeoipDatabase = rb_define_class_under(rb_cRgeoip, "Database", rb_cObject);
|
481
644
|
rb_define_alloc_func(rb_cRgeoipDatabase, gid_alloc);
|
482
645
|
rb_define_method(rb_cRgeoipDatabase, "initialize", gid_new, -1);
|
483
646
|
rb_define_method(rb_cRgeoipDatabase, "country", gid_country, 1);
|
484
647
|
rb_define_method(rb_cRgeoipDatabase, "city", gid_city, 1);
|
648
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
649
|
+
rb_define_method(rb_cRgeoipDatabase, "encoding=", gid_set_encoding, 1);
|
650
|
+
rb_define_method(rb_cRgeoipDatabase, "encoding", gid_get_encoding, 0);
|
651
|
+
#endif
|
485
652
|
|
486
653
|
rgeoip_symbols[RS_CODE] = ID2SYM(rb_intern("code"));
|
487
654
|
rgeoip_symbols[RS_CODE3] = ID2SYM(rb_intern("code3"));
|
@@ -493,4 +660,11 @@ Init_rgeoip(void)
|
|
493
660
|
rgeoip_symbols[RS_LONGITUDE] = ID2SYM(rb_intern("longitude"));
|
494
661
|
rgeoip_symbols[RS_DMA_CODE] = ID2SYM(rb_intern("dma_code"));
|
495
662
|
rgeoip_symbols[RS_AREA_CODE] = ID2SYM(rb_intern("area_code"));
|
663
|
+
|
664
|
+
i_to_s = rb_intern("to_s");
|
665
|
+
|
666
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
667
|
+
enc_utf8 = rb_utf8_encoding();
|
668
|
+
enc_iso_8859_1 = rb_enc_find("ISO-8859-1");
|
669
|
+
#endif
|
496
670
|
}
|
data/rgeoip.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rgeoip}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["miyucy"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-23}
|
13
13
|
s.description = %q{alternative libGeoIP binding for Ruby}
|
14
14
|
s.email = %q{miyucy@gmail.com}
|
15
15
|
s.extensions = ["ext/extconf.rb"]
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
|
+
".gemtest",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -27,24 +28,28 @@ Gem::Specification.new do |s|
|
|
27
28
|
"VERSION",
|
28
29
|
"ext/extconf.rb",
|
29
30
|
"ext/rgeoip.c",
|
31
|
+
"lib/rack/rgeoip.rb",
|
30
32
|
"rgeoip.gemspec",
|
33
|
+
"test/data/GeoIP.dat",
|
34
|
+
"test/data/GeoLiteCity.dat",
|
31
35
|
"test/helper.rb",
|
36
|
+
"test/test_rack_rgeoip_lookup.rb",
|
32
37
|
"test/test_rgeoip.rb",
|
33
38
|
"test/test_rgeoip_database.rb"
|
34
39
|
]
|
35
40
|
s.homepage = %q{http://github.com/miyucy/rgeoip}
|
36
41
|
s.licenses = ["LGPL"]
|
37
42
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.
|
43
|
+
s.rubygems_version = %q{1.5.2}
|
39
44
|
s.summary = %q{alternative libGeoIP binding for Ruby}
|
40
45
|
s.test_files = [
|
41
46
|
"test/helper.rb",
|
47
|
+
"test/test_rack_rgeoip_lookup.rb",
|
42
48
|
"test/test_rgeoip.rb",
|
43
49
|
"test/test_rgeoip_database.rb"
|
44
50
|
]
|
45
51
|
|
46
52
|
if s.respond_to? :specification_version then
|
47
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
53
|
s.specification_version = 3
|
49
54
|
|
50
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -53,12 +58,14 @@ Gem::Specification.new do |s|
|
|
53
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
59
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
60
|
s.add_development_dependency(%q<ZenTest>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rack>, [">= 0"])
|
56
62
|
else
|
57
63
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
58
64
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
65
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
66
|
s.add_dependency(%q<rcov>, [">= 0"])
|
61
67
|
s.add_dependency(%q<ZenTest>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
62
69
|
end
|
63
70
|
else
|
64
71
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
@@ -66,6 +73,7 @@ Gem::Specification.new do |s|
|
|
66
73
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
74
|
s.add_dependency(%q<rcov>, [">= 0"])
|
68
75
|
s.add_dependency(%q<ZenTest>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
data/test/test_rgeoip.rb
CHANGED
@@ -28,7 +28,7 @@ class TestRgeoip < Test::Unit::TestCase
|
|
28
28
|
Rgeoip.new.open Tempfile.new("rgeoip").path
|
29
29
|
}
|
30
30
|
|
31
|
-
assert_raise(
|
31
|
+
assert_raise(RuntimeError) {
|
32
32
|
Rgeoip.new.open nil
|
33
33
|
}
|
34
34
|
end
|
@@ -44,7 +44,7 @@ class TestRgeoip < Test::Unit::TestCase
|
|
44
44
|
Rgeoip.new.open [Tempfile.new("rgeoip").path, Tempfile.new("rgeoip").path]
|
45
45
|
}
|
46
46
|
|
47
|
-
assert_raise(
|
47
|
+
assert_raise(RuntimeError) {
|
48
48
|
Rgeoip.new.open [nil]
|
49
49
|
}
|
50
50
|
end
|
@@ -63,6 +63,46 @@ class TestRgeoip < Test::Unit::TestCase
|
|
63
63
|
assert_equal("Tokyo", rgeoip.city("202.12.27.33")[:city])
|
64
64
|
end
|
65
65
|
|
66
|
+
def test_get_encoding
|
67
|
+
assert_equal(Encoding, rgeoip.encoding.class)
|
68
|
+
end if defined? Encoding
|
69
|
+
|
70
|
+
def test_set_invalid_encoding
|
71
|
+
@rgeoip = rgeoip
|
72
|
+
encoding = @rgeoip.encoding
|
73
|
+
|
74
|
+
assert_raise(RuntimeError) {
|
75
|
+
@rgeoip.encoding = Encoding.find("Shift_JIS")
|
76
|
+
}
|
77
|
+
assert_raise(RuntimeError) {
|
78
|
+
@rgeoip.encoding = "Shift_JIS"
|
79
|
+
}
|
80
|
+
|
81
|
+
assert_equal(encoding, @rgeoip.encoding)
|
82
|
+
end if defined? Encoding
|
83
|
+
|
84
|
+
def test_set_encoding_iso_8859_1
|
85
|
+
@rgeoip = rgeoip
|
86
|
+
enc_iso8859_1 = Encoding.find("ISO-8859-1")
|
87
|
+
|
88
|
+
@rgeoip.encoding = "ISO-8859-1"
|
89
|
+
assert_equal(enc_iso8859_1, @rgeoip.encoding)
|
90
|
+
|
91
|
+
@rgeoip.encoding = enc_iso8859_1
|
92
|
+
assert_equal(enc_iso8859_1, @rgeoip.encoding)
|
93
|
+
end if defined? Encoding
|
94
|
+
|
95
|
+
def test_set_encoding_utf8
|
96
|
+
@rgeoip = rgeoip
|
97
|
+
enc_utf8 = Encoding.find("UTF-8")
|
98
|
+
|
99
|
+
@rgeoip.encoding = "UTF-8"
|
100
|
+
assert_equal(enc_utf8, @rgeoip.encoding)
|
101
|
+
|
102
|
+
@rgeoip.encoding = enc_utf8
|
103
|
+
assert_equal(enc_utf8, @rgeoip.encoding)
|
104
|
+
end if defined? Encoding
|
105
|
+
|
66
106
|
private
|
67
107
|
|
68
108
|
def paths
|
@@ -72,6 +72,68 @@ class TestRgeoipDatabase < Test::Unit::TestCase
|
|
72
72
|
assert_equal(nil, city_db.city("1.2.3.4.5"))
|
73
73
|
end
|
74
74
|
|
75
|
+
def test_get_encoding
|
76
|
+
assert_equal(Encoding, city_db.encoding.class)
|
77
|
+
end if defined? Encoding
|
78
|
+
|
79
|
+
def test_set_invalid_encoding
|
80
|
+
@city_db = city_db
|
81
|
+
encoding = @city_db.encoding
|
82
|
+
|
83
|
+
assert_raise(RuntimeError) {
|
84
|
+
@city_db.encoding = Encoding.find("Shift_JIS")
|
85
|
+
}
|
86
|
+
|
87
|
+
assert_raise(RuntimeError) {
|
88
|
+
@city_db.encoding = "Shift_JIS"
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_equal(encoding, @city_db.encoding)
|
92
|
+
end if defined? Encoding
|
93
|
+
|
94
|
+
def test_set_encoding_utf8
|
95
|
+
@city_db = city_db
|
96
|
+
enc_utf8 = Encoding.find("UTF-8")
|
97
|
+
|
98
|
+
@city_db.encoding = "UTF-8"
|
99
|
+
assert_equal(enc_utf8, @city_db.encoding)
|
100
|
+
|
101
|
+
@city_db.encoding = enc_utf8
|
102
|
+
assert_equal(enc_utf8, @city_db.encoding)
|
103
|
+
end if defined? Encoding
|
104
|
+
|
105
|
+
def test_set_encoding_iso_8859_1
|
106
|
+
@city_db = city_db
|
107
|
+
enc_iso8859_1 = Encoding.find("ISO-8859-1")
|
108
|
+
|
109
|
+
@city_db.encoding = "ISO-8859-1"
|
110
|
+
assert_equal(enc_iso8859_1, @city_db.encoding)
|
111
|
+
|
112
|
+
@city_db.encoding = enc_iso8859_1
|
113
|
+
assert_equal(enc_iso8859_1, @city_db.encoding)
|
114
|
+
end if defined? Encoding
|
115
|
+
|
116
|
+
def test_encoding_utf8
|
117
|
+
@city_db = city_db
|
118
|
+
@city_db.encoding = "UTF-8"
|
119
|
+
assert_equal(@city_db.encoding, @city_db.city("m.root-servers.net")[:city].encoding)
|
120
|
+
end if defined? Encoding
|
121
|
+
|
122
|
+
def test_encoding_utf8
|
123
|
+
@city_db = city_db
|
124
|
+
@city_db.encoding = "ISO-8859-1"
|
125
|
+
assert_equal(@city_db.encoding, @city_db.city("m.root-servers.net")[:city].encoding)
|
126
|
+
end if defined? Encoding
|
127
|
+
|
128
|
+
def test_default_internal
|
129
|
+
di = Encoding.default_internal
|
130
|
+
|
131
|
+
Encoding.default_internal = "Shift_JIS"
|
132
|
+
assert_equal(Encoding.default_internal, city_db.city("m.root-servers.net")[:city].encoding)
|
133
|
+
|
134
|
+
Encoding.default_internal = di
|
135
|
+
end if defined? Encoding
|
136
|
+
|
75
137
|
private
|
76
138
|
|
77
139
|
def paths
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
5
|
+
version: 0.0.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- miyucy
|
@@ -15,99 +10,75 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-03-23 00:00:00 +09:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
17
|
+
name: yard
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
21
|
- - ~>
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 7
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 6
|
32
|
-
- 0
|
33
23
|
version: 0.6.0
|
34
|
-
|
35
|
-
version_requirements: *id001
|
24
|
+
type: :development
|
36
25
|
prerelease: false
|
26
|
+
version_requirements: *id001
|
37
27
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
28
|
+
name: bundler
|
39
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
30
|
none: false
|
41
31
|
requirements:
|
42
32
|
- - ~>
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 23
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
- 0
|
49
34
|
version: 1.0.0
|
50
|
-
|
51
|
-
version_requirements: *id002
|
35
|
+
type: :development
|
52
36
|
prerelease: false
|
37
|
+
version_requirements: *id002
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
39
|
+
name: jeweler
|
55
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
41
|
none: false
|
57
42
|
requirements:
|
58
43
|
- - ~>
|
59
44
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 7
|
61
|
-
segments:
|
62
|
-
- 1
|
63
|
-
- 5
|
64
|
-
- 2
|
65
45
|
version: 1.5.2
|
66
|
-
|
67
|
-
version_requirements: *id003
|
46
|
+
type: :development
|
68
47
|
prerelease: false
|
48
|
+
version_requirements: *id003
|
69
49
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
50
|
+
name: rcov
|
71
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
52
|
none: false
|
73
53
|
requirements:
|
74
54
|
- - ">="
|
75
55
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
56
|
version: "0"
|
80
|
-
|
81
|
-
version_requirements: *id004
|
57
|
+
type: :development
|
82
58
|
prerelease: false
|
59
|
+
version_requirements: *id004
|
83
60
|
- !ruby/object:Gem::Dependency
|
84
|
-
|
61
|
+
name: ZenTest
|
85
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
63
|
none: false
|
87
64
|
requirements:
|
88
65
|
- - ">="
|
89
66
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
|
-
segments:
|
92
|
-
- 0
|
93
67
|
version: "0"
|
94
|
-
|
95
|
-
version_requirements: *id005
|
68
|
+
type: :development
|
96
69
|
prerelease: false
|
70
|
+
version_requirements: *id005
|
97
71
|
- !ruby/object:Gem::Dependency
|
98
|
-
|
72
|
+
name: rack
|
99
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
100
74
|
none: false
|
101
75
|
requirements:
|
102
76
|
- - ">="
|
103
77
|
- !ruby/object:Gem::Version
|
104
|
-
hash: 3
|
105
|
-
segments:
|
106
|
-
- 0
|
107
78
|
version: "0"
|
108
|
-
|
109
|
-
version_requirements: *id006
|
79
|
+
type: :development
|
110
80
|
prerelease: false
|
81
|
+
version_requirements: *id006
|
111
82
|
description: alternative libGeoIP binding for Ruby
|
112
83
|
email: miyucy@gmail.com
|
113
84
|
executables: []
|
@@ -150,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
121
|
requirements:
|
151
122
|
- - ">="
|
152
123
|
- !ruby/object:Gem::Version
|
153
|
-
hash:
|
124
|
+
hash: 2012554838246895694
|
154
125
|
segments:
|
155
126
|
- 0
|
156
127
|
version: "0"
|
@@ -159,9 +130,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
130
|
requirements:
|
160
131
|
- - ">="
|
161
132
|
- !ruby/object:Gem::Version
|
162
|
-
hash: 3
|
163
|
-
segments:
|
164
|
-
- 0
|
165
133
|
version: "0"
|
166
134
|
requirements: []
|
167
135
|
|