libcdb-ruby 0.0.1
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.
- data/.rspec +1 -0
- data/COPYING +663 -0
- data/ChangeLog +5 -0
- data/README +96 -0
- data/Rakefile +30 -0
- data/TODO +4 -0
- data/ext/libcdb/extconf.rb +11 -0
- data/ext/libcdb/libcdb.c +16 -0
- data/ext/libcdb/libcdb_ruby.def +8 -0
- data/ext/libcdb/ruby_cdb.c +15 -0
- data/ext/libcdb/ruby_cdb.h +13 -0
- data/ext/libcdb/ruby_cdb_reader.c +677 -0
- data/ext/libcdb/ruby_cdb_reader.h +30 -0
- data/ext/libcdb/ruby_cdb_writer.c +301 -0
- data/ext/libcdb/ruby_cdb_writer.h +16 -0
- data/ext/libcdb/ruby_libcdb.h +27 -0
- data/lib/cdb.rb +2 -0
- data/lib/libcdb/version.rb +31 -0
- data/lib/libcdb-ruby.rb +1 -0
- data/lib/libcdb.rb +256 -0
- data/spec/libcdb/reader_spec.rb +142 -0
- data/spec/libcdb/writer_spec.rb +34 -0
- data/spec/spec_helper.rb +21 -0
- metadata +100 -0
data/README
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
= libcdb-ruby - Ruby bindings for CDB Constant Databases.
|
2
|
+
|
3
|
+
== VERSION
|
4
|
+
|
5
|
+
This documentation refers to libcdb-ruby version 0.0.1
|
6
|
+
|
7
|
+
|
8
|
+
== DESCRIPTION
|
9
|
+
|
10
|
+
The libcdb-ruby library provides Ruby bindings for the
|
11
|
+
TinyCDB[http://corpit.ru/mjt/tinycdb.html] package for
|
12
|
+
creating and reading {constant databases}[http://cr.yp.to/cdb.html].
|
13
|
+
|
14
|
+
require 'libcdb'
|
15
|
+
|
16
|
+
# creating
|
17
|
+
LibCDB::CDB.open('foo.cdb', 'w') { |cdb|
|
18
|
+
cdb['a'] = 'one'
|
19
|
+
cdb['b'] = '123'
|
20
|
+
}
|
21
|
+
|
22
|
+
# reading
|
23
|
+
LibCDB::CDB.open('foo.cdb') { |cdb|
|
24
|
+
cdb['a'] #=> "one"
|
25
|
+
cdb['b'] #=> "123"
|
26
|
+
cdb['c'] #=> nil
|
27
|
+
}
|
28
|
+
|
29
|
+
# hybrid
|
30
|
+
LibCDB::CDB.open('foo.cdb', 'w+') { |cdb|
|
31
|
+
cdb['a'] = 'one'
|
32
|
+
cdb['b'] = '123'
|
33
|
+
|
34
|
+
cdb['a'] #=> "one"
|
35
|
+
cdb['b'] #=> "123"
|
36
|
+
cdb['c'] #=> nil
|
37
|
+
|
38
|
+
cdb['a'] = 'two'
|
39
|
+
cdb['c'] = 'xyz'
|
40
|
+
|
41
|
+
cdb['a'] #=> "two"
|
42
|
+
cdb['b'] #=> nil
|
43
|
+
cdb['c'] #=> "xyz"
|
44
|
+
}
|
45
|
+
|
46
|
+
# update existing database
|
47
|
+
LibCDB::CDB.open('foo.cdb', 'r+') { |cdb|
|
48
|
+
cdb.store(cdb.to_h)
|
49
|
+
|
50
|
+
cdb['d'] = '42'
|
51
|
+
|
52
|
+
cdb['a'] #=> "two"
|
53
|
+
cdb['b'] #=> nil
|
54
|
+
cdb['c'] #=> "xyz"
|
55
|
+
cdb['d'] #=> "42"
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
== SUPPORTED PLATFORMS
|
60
|
+
|
61
|
+
Linux:: 1.8 & 1.9
|
62
|
+
Windows:: 1.9 only
|
63
|
+
|
64
|
+
|
65
|
+
== LINKS
|
66
|
+
|
67
|
+
<b></b>
|
68
|
+
Documentation:: http://blackwinter.github.com/libcdb-ruby
|
69
|
+
Source code:: http://github.com/blackwinter/libcdb-ruby
|
70
|
+
RubyGem:: http://rubygems.org/gems/libcdb-ruby
|
71
|
+
TinyCDB:: http://corpit.ru/mjt/tinycdb.html
|
72
|
+
CDB:: http://cr.yp.to/cdb.html
|
73
|
+
|
74
|
+
|
75
|
+
== AUTHORS
|
76
|
+
|
77
|
+
* Jens Wille <mailto:jens.wille@uni-koeln.de>
|
78
|
+
|
79
|
+
|
80
|
+
== LICENSE AND COPYRIGHT
|
81
|
+
|
82
|
+
Copyright (C) 2012 University of Cologne,
|
83
|
+
Albertus-Magnus-Platz, 50923 Cologne, Germany
|
84
|
+
|
85
|
+
libcdb-ruby is free software: you can redistribute it and/or modify it
|
86
|
+
under the terms of the GNU Affero General Public License as published by
|
87
|
+
the Free Software Foundation, either version 3 of the License, or (at your
|
88
|
+
option) any later version.
|
89
|
+
|
90
|
+
libcdb-ruby is distributed in the hope that it will be useful, but
|
91
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
92
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
93
|
+
License for more details.
|
94
|
+
|
95
|
+
You should have received a copy of the GNU Affero General Public License
|
96
|
+
along with libcdb-ruby. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(%q{../lib/libcdb/version}, __FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'hen'
|
5
|
+
|
6
|
+
cco = []
|
7
|
+
|
8
|
+
if dir = ENV['TINYCDB']
|
9
|
+
cco << "--with-cdb-include=#{dir}"
|
10
|
+
cco << "--with-cdb-lib=#{dir}"
|
11
|
+
end
|
12
|
+
|
13
|
+
if dir = ENV['MINGW32']
|
14
|
+
cco << "--with-cflags=\"-I#{dir}/include -L#{dir}/lib\""
|
15
|
+
end
|
16
|
+
|
17
|
+
Hen.lay! {{
|
18
|
+
:gem => {
|
19
|
+
:name => %q{libcdb-ruby},
|
20
|
+
:version => LibCDB::CDB::VERSION,
|
21
|
+
:summary => %q{Ruby bindings for CDB Constant Databases.},
|
22
|
+
:author => %q{Jens Wille},
|
23
|
+
:email => %q{jens.wille@uni-koeln.de},
|
24
|
+
:homepage => :blackwinter,
|
25
|
+
:extension => { :cross_config_options => cco }
|
26
|
+
}
|
27
|
+
}}
|
28
|
+
rescue LoadError => err
|
29
|
+
warn "Please install the `hen' gem. (#{err})"
|
30
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('cdb')
|
4
|
+
|
5
|
+
if have_library('cdb', 'cdb_init') && have_header('cdb.h') && have_macro('TINYCDB_VERSION', 'cdb.h')
|
6
|
+
have_header('ruby/io.h')
|
7
|
+
have_header('ruby/st.h')
|
8
|
+
create_makefile('libcdb/libcdb_ruby')
|
9
|
+
else
|
10
|
+
abort '*** ERROR: missing required library to compile this module'
|
11
|
+
end
|
data/ext/libcdb/libcdb.c
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#include "ruby_libcdb.h"
|
2
|
+
|
3
|
+
void
|
4
|
+
Init_libcdb_ruby(void) {
|
5
|
+
char libcdb_version[8];
|
6
|
+
snprintf(libcdb_version, 7, "%g", TINYCDB_VERSION);
|
7
|
+
|
8
|
+
/*
|
9
|
+
* LibCDB namespace.
|
10
|
+
*/
|
11
|
+
mLibCDB = rb_define_module("LibCDB");
|
12
|
+
|
13
|
+
rcdb_init_cdb();
|
14
|
+
rcdb_init_reader();
|
15
|
+
rcdb_init_writer();
|
16
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "ruby_libcdb.h"
|
2
|
+
|
3
|
+
void
|
4
|
+
rcdb_init_cdb(void) {
|
5
|
+
char libcdb_version[8];
|
6
|
+
snprintf(libcdb_version, 7, "%g", TINYCDB_VERSION);
|
7
|
+
|
8
|
+
/*
|
9
|
+
* See README.
|
10
|
+
*/
|
11
|
+
cCDB = rb_define_class_under(mLibCDB, "CDB", rb_cObject);
|
12
|
+
|
13
|
+
/* The TinyCDB library version. */
|
14
|
+
rb_define_const(cCDB, "LIBCDB_VERSION", rb_str_new2(libcdb_version));
|
15
|
+
}
|