faststep 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/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Rakefile +15 -0
- data/bench/standard_benchmark +178 -0
- data/ext/faststep/bson.c +687 -0
- data/ext/faststep/bson.h +225 -0
- data/ext/faststep/bson_ruby_conversion.c +44 -0
- data/ext/faststep/bson_ruby_conversion.h +10 -0
- data/ext/faststep/collection.c +187 -0
- data/ext/faststep/collection.h +24 -0
- data/ext/faststep/connection.c +85 -0
- data/ext/faststep/connection.h +17 -0
- data/ext/faststep/cursor.c +61 -0
- data/ext/faststep/cursor.h +10 -0
- data/ext/faststep/db.c +56 -0
- data/ext/faststep/db.h +8 -0
- data/ext/faststep/exceptions.c +7 -0
- data/ext/faststep/exceptions.h +5 -0
- data/ext/faststep/extconf.rb +3 -0
- data/ext/faststep/faststep.c +30 -0
- data/ext/faststep/faststep.h +4 -0
- data/ext/faststep/faststep_defines.h +11 -0
- data/ext/faststep/gridfs.c +799 -0
- data/ext/faststep/gridfs.h +278 -0
- data/ext/faststep/md5.c +381 -0
- data/ext/faststep/md5.h +91 -0
- data/ext/faststep/mongo.c +801 -0
- data/ext/faststep/mongo.h +188 -0
- data/ext/faststep/mongo_except.h +143 -0
- data/ext/faststep/numbers.c +127 -0
- data/ext/faststep/platform_hacks.h +93 -0
- data/ext/faststep/support.c +21 -0
- data/ext/faststep/support.h +6 -0
- data/faststep.gemspec +26 -0
- data/lib/faststep/collection.rb +21 -0
- data/lib/faststep/connection.rb +13 -0
- data/lib/faststep/cursor.rb +7 -0
- data/lib/faststep/db.rb +25 -0
- data/lib/faststep/version.rb +3 -0
- data/lib/faststep.rb +10 -0
- data/spec/collection_spec.rb +116 -0
- data/spec/connection_spec.rb +34 -0
- data/spec/cursor_spec.rb +24 -0
- data/spec/db_spec.rb +28 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support_spec.rb +14 -0
- metadata +181 -0
data/ext/faststep/db.c
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#include "db.h"
|
2
|
+
#include "mongo.h"
|
3
|
+
#include "bson.h"
|
4
|
+
#include "connection.h"
|
5
|
+
#include "collection.h"
|
6
|
+
#include "bson_ruby_conversion.h"
|
7
|
+
#include "faststep_defines.h"
|
8
|
+
|
9
|
+
void faststep_db_main() {
|
10
|
+
rb_cFaststepDb = rb_define_class_under(rb_mFaststep, "Db", rb_cObject);
|
11
|
+
|
12
|
+
rb_define_attr(rb_cFaststepDb, "name", 1, 0);
|
13
|
+
rb_define_attr(rb_cFaststepDb, "connection", 1, 0);
|
14
|
+
|
15
|
+
rb_define_alias(rb_cFaststepDb, "[]", "collection");
|
16
|
+
|
17
|
+
rb_define_method(rb_cFaststepDb, "initialize", faststep_db_init, 2);
|
18
|
+
rb_define_method(rb_cFaststepDb, "drop", faststep_db_drop, 0);
|
19
|
+
rb_define_method(rb_cFaststepDb, "command", faststep_db_command, 1);
|
20
|
+
}
|
21
|
+
|
22
|
+
static VALUE faststep_db_init(VALUE self, VALUE name, VALUE connection) {
|
23
|
+
rb_iv_set(self, "@name", name);
|
24
|
+
rb_iv_set(self, "@connection", connection);
|
25
|
+
|
26
|
+
return self;
|
27
|
+
}
|
28
|
+
|
29
|
+
static VALUE faststep_db_drop(VALUE self) {
|
30
|
+
mongo_connection* conn = GetFaststepConnection(rb_iv_get(self, "@connection"));
|
31
|
+
|
32
|
+
return bool_to_ruby(mongo_cmd_drop_db(conn, RSTRING_PTR(rb_iv_get(self, "@name"))));
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE faststep_db_command(VALUE self, VALUE command) {
|
36
|
+
mongo_connection* conn = GetFaststepConnection(rb_iv_get(self, "@connection"));
|
37
|
+
|
38
|
+
bson* result = bson_malloc(sizeof(bson));
|
39
|
+
bson_init(result, "", 1);
|
40
|
+
|
41
|
+
bson* bson_command = create_bson_from_ruby_hash(command);
|
42
|
+
|
43
|
+
char ns[500] = "";
|
44
|
+
build_collection_ns(ns, RSTRING_PTR(rb_iv_get(self, "@name")), "$cmd");
|
45
|
+
|
46
|
+
mongo_find_one(conn, ns, bson_command, NULL, result);
|
47
|
+
|
48
|
+
bson_destroy(bson_command);
|
49
|
+
|
50
|
+
VALUE hash = ruby_hash_from_bson(result);
|
51
|
+
bson_destroy(result);
|
52
|
+
|
53
|
+
ensure_document_ok(hash);
|
54
|
+
|
55
|
+
return hash;
|
56
|
+
}
|
data/ext/faststep/db.h
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#include "exceptions.h"
|
2
|
+
#include "faststep_defines.h"
|
3
|
+
|
4
|
+
void faststep_exceptions_main() {
|
5
|
+
rb_cFaststepConnectionFailure = rb_define_class_under(rb_mFaststep, "ConnectionFailure", rb_eStandardError);
|
6
|
+
rb_cFaststepOperationFailure = rb_define_class_under(rb_mFaststep, "OperationFailure", rb_eStandardError);
|
7
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#include "faststep.h"
|
2
|
+
#include "connection.h"
|
3
|
+
#include "db.h"
|
4
|
+
#include "collection.h"
|
5
|
+
#include "exceptions.h"
|
6
|
+
#include "cursor.h"
|
7
|
+
#include "support.h"
|
8
|
+
|
9
|
+
VALUE rb_mBson;
|
10
|
+
VALUE rb_mFaststep;
|
11
|
+
VALUE rb_cFaststepConnection;
|
12
|
+
VALUE rb_cFaststepDb;
|
13
|
+
VALUE rb_cFaststepCollection;
|
14
|
+
VALUE rb_cFaststepCursor;
|
15
|
+
VALUE rb_mFaststepSupport;
|
16
|
+
|
17
|
+
VALUE rb_cFaststepConnectionFailure;
|
18
|
+
VALUE rb_cFaststepOperationFailure;
|
19
|
+
|
20
|
+
void Init_faststep() {
|
21
|
+
rb_mFaststep = rb_define_module("Faststep");
|
22
|
+
rb_mBson = rb_const_get(rb_cObject, rb_intern("BSON"));
|
23
|
+
|
24
|
+
faststep_connection_main();
|
25
|
+
faststep_db_main();
|
26
|
+
faststep_collection_main();
|
27
|
+
faststep_cursor_main();
|
28
|
+
faststep_support_main();
|
29
|
+
faststep_exceptions_main();
|
30
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
RUBY_EXTERN VALUE rb_mFaststep;
|
2
|
+
RUBY_EXTERN VALUE rb_mFaststepSupport;
|
3
|
+
RUBY_EXTERN VALUE rb_cFaststepConnection;
|
4
|
+
RUBY_EXTERN VALUE rb_cFaststepDb;
|
5
|
+
RUBY_EXTERN VALUE rb_cFaststepCollection;
|
6
|
+
RUBY_EXTERN VALUE rb_cFaststepCursor;
|
7
|
+
|
8
|
+
RUBY_EXTERN VALUE rb_cFaststepConnectionFailure;
|
9
|
+
RUBY_EXTERN VALUE rb_cFaststepOperationFailure;
|
10
|
+
|
11
|
+
RUBY_EXTERN VALUE rb_mBson;
|