libcdb-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,4 @@
1
+ * More specs!!
2
+ * More Documentation!
3
+ * Atomic updates? (rename after create)
4
+ * Benchmarks?
@@ -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
@@ -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,8 @@
1
+ LIBRARY libcdb_ruby.so
2
+ EXPORTS
3
+ Init_libcdb_ruby
4
+
5
+ cCDBReader DATA
6
+ cCDBWriter DATA
7
+ mLibCDB DATA
8
+ cCDB DATA
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef __RUBY_CDB_H__
2
+ #define __RUBY_CDB_H__
3
+
4
+ #ifdef HAVE_RUBY_IO_H
5
+ #define GetFileFD(fptr) (fptr)->fd
6
+ #else
7
+ #define GetFileFD(fptr) fileno((fptr)->f)
8
+ #endif
9
+
10
+ VALUE cCDB;
11
+ void rcdb_init_cdb(void);
12
+
13
+ #endif /* __RUBY_CDB_H__ */