faststep 0.0.7 → 0.0.8
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/ext/faststep/collection.c +0 -17
- data/ext/faststep/collection.h +0 -2
- data/ext/faststep/connection.c +1 -12
- data/ext/faststep/connection.h +0 -1
- data/ext/faststep/cursor.c +0 -21
- data/ext/faststep/cursor.h +0 -3
- data/ext/faststep/db.c +0 -13
- data/ext/faststep/db.h +0 -1
- data/lib/faststep/collection.rb +15 -1
- data/lib/faststep/connection.rb +10 -0
- data/lib/faststep/cursor.rb +19 -0
- data/lib/faststep/db.rb +9 -0
- data/lib/faststep/version.rb +1 -1
- metadata +2 -2
data/ext/faststep/collection.c
CHANGED
@@ -8,11 +8,6 @@
|
|
8
8
|
void faststep_collection_main() {
|
9
9
|
rb_cFaststepCollection = rb_define_class_under(rb_mFaststep, "Collection", rb_cObject);
|
10
10
|
|
11
|
-
rb_define_attr(rb_cFaststepCollection, "name", 1, 0);
|
12
|
-
rb_define_attr(rb_cFaststepCollection, "db", 1, 0);
|
13
|
-
|
14
|
-
rb_define_method(rb_cFaststepCollection, "initialize", faststep_collection_init, 2);
|
15
|
-
rb_define_method(rb_cFaststepCollection, "connection", faststep_collection_connection, 0);
|
16
11
|
rb_define_method(rb_cFaststepCollection, "ns", faststep_collection_ns, 0);
|
17
12
|
rb_define_method(rb_cFaststepCollection, "find", faststep_collection_find, -1);
|
18
13
|
rb_define_method(rb_cFaststepCollection, "find_one", faststep_collection_find_one, -1);
|
@@ -25,18 +20,6 @@ void faststep_collection_main() {
|
|
25
20
|
return;
|
26
21
|
}
|
27
22
|
|
28
|
-
static VALUE faststep_collection_init(VALUE self, const VALUE name, const VALUE database) {
|
29
|
-
rb_iv_set(self, "@name", name);
|
30
|
-
rb_iv_set(self, "@db", database);
|
31
|
-
|
32
|
-
return self;
|
33
|
-
}
|
34
|
-
|
35
|
-
static VALUE faststep_collection_connection(const VALUE self) {
|
36
|
-
VALUE db = rb_iv_get(self, "@db");
|
37
|
-
return rb_iv_get(db, "@connection");
|
38
|
-
}
|
39
|
-
|
40
23
|
VALUE faststep_collection_ns(const VALUE self) {
|
41
24
|
VALUE db_name = rb_str_new2(_ivar_name(rb_iv_get(self, "@db")));
|
42
25
|
VALUE collection_name = rb_str_new2(_ivar_name(self));
|
data/ext/faststep/collection.h
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
#define COLLECTION_H
|
6
6
|
|
7
7
|
void faststep_collection_main();
|
8
|
-
static VALUE faststep_collection_init(VALUE, const VALUE, const VALUE);
|
9
|
-
static VALUE faststep_collection_connection(const VALUE);
|
10
8
|
static VALUE faststep_collection_find(int, VALUE*, const VALUE);
|
11
9
|
static VALUE faststep_collection_find_one(int, VALUE*, const VALUE);
|
12
10
|
static VALUE faststep_collection_count(int, VALUE*, VALUE);
|
data/ext/faststep/connection.c
CHANGED
@@ -4,10 +4,6 @@
|
|
4
4
|
|
5
5
|
void faststep_connection_main() {
|
6
6
|
rb_cFaststepConnection = rb_define_class_under(rb_mFaststep, "Connection", rb_cObject);
|
7
|
-
rb_define_const(rb_cFaststepConnection, "DEFAULT_PORT", INT2FIX(27017));
|
8
|
-
|
9
|
-
rb_define_attr(rb_cFaststepConnection, "host", 1, 0);
|
10
|
-
rb_define_attr(rb_cFaststepConnection, "port", 1, 0);
|
11
7
|
|
12
8
|
rb_define_singleton_method(rb_cFaststepConnection, "new", faststep_connection_new, -1);
|
13
9
|
|
@@ -16,9 +12,6 @@ void faststep_connection_main() {
|
|
16
12
|
rb_define_method(rb_cFaststepConnection, "disconnect!", faststep_connection_disconnect, 0);
|
17
13
|
rb_define_method(rb_cFaststepConnection, "connected?", faststep_connection_connected, 0);
|
18
14
|
rb_define_method(rb_cFaststepConnection, "master?", faststep_connection_master, 0);
|
19
|
-
rb_define_method(rb_cFaststepConnection, "db", faststep_connection_db, 1);
|
20
|
-
|
21
|
-
rb_define_alias(rb_cFaststepConnection, "[]", "db");
|
22
15
|
|
23
16
|
return;
|
24
17
|
}
|
@@ -29,7 +22,7 @@ static VALUE faststep_connection_init(int argc, VALUE* argv, VALUE self) {
|
|
29
22
|
rb_scan_args(argc, argv, "02", &host, &port);
|
30
23
|
|
31
24
|
if(!RTEST(host)) { host = rb_str_new2("127.0.0.1"); }
|
32
|
-
if(!RTEST(port)) { port =
|
25
|
+
if(!RTEST(port)) { port = rb_const_get(rb_cFaststepConnection, rb_intern("DEFAULT_PORT")); }
|
33
26
|
|
34
27
|
rb_iv_set(self, "@host", host);
|
35
28
|
rb_iv_set(self, "@port", port);
|
@@ -74,10 +67,6 @@ static VALUE faststep_connection_master(const VALUE self) {
|
|
74
67
|
return bool_to_ruby(mongo_cmd_ismaster(GetFaststepConnection(self), NULL));
|
75
68
|
}
|
76
69
|
|
77
|
-
static VALUE faststep_connection_db(const VALUE self, const VALUE database_name) {
|
78
|
-
return rb_funcall(rb_cFaststepDb, rb_intern("new"), 2, database_name, self);
|
79
|
-
}
|
80
|
-
|
81
70
|
static void _faststep_connect_or_raise(mongo_connection* conn, mongo_connection_options* options) {
|
82
71
|
mongo_connect(conn, options);
|
83
72
|
|
data/ext/faststep/connection.h
CHANGED
@@ -10,7 +10,6 @@ static VALUE faststep_connection_connect(VALUE);
|
|
10
10
|
static VALUE faststep_connection_disconnect(const VALUE);
|
11
11
|
static VALUE faststep_connection_connected(const VALUE);
|
12
12
|
static VALUE faststep_connection_master(const VALUE);
|
13
|
-
static VALUE faststep_connection_db(const VALUE, const VALUE);
|
14
13
|
|
15
14
|
mongo_connection* GetFaststepConnection(const VALUE);
|
16
15
|
|
data/ext/faststep/cursor.c
CHANGED
@@ -6,16 +6,10 @@
|
|
6
6
|
void faststep_cursor_main() {
|
7
7
|
rb_cFaststepCursor = rb_define_class_under(rb_mFaststep, "Cursor", rb_cObject);
|
8
8
|
|
9
|
-
rb_define_attr(rb_cFaststepCursor, "collection", 1, 0);
|
10
|
-
rb_include_module(rb_cFaststepCursor, rb_mEnumerable);
|
11
|
-
|
12
9
|
rb_define_singleton_method(rb_cFaststepCursor, "new", faststep_cursor_new, -1);
|
13
10
|
|
14
11
|
rb_define_method(rb_cFaststepCursor, "initialize", faststep_cursor_init, -1);
|
15
12
|
rb_define_method(rb_cFaststepCursor, "explain", faststep_cursor_explain, 0);
|
16
|
-
rb_define_method(rb_cFaststepCursor, "skip", faststep_cursor_skip, 1);
|
17
|
-
rb_define_method(rb_cFaststepCursor, "limit", faststep_cursor_limit, 1);
|
18
|
-
rb_define_method(rb_cFaststepCursor, "fields", faststep_cursor_fields, 1);
|
19
13
|
rb_define_method(rb_cFaststepCursor, "order", faststep_cursor_order, 1);
|
20
14
|
rb_define_method(rb_cFaststepCursor, "each", faststep_cursor_each, 0);
|
21
15
|
|
@@ -80,21 +74,6 @@ static VALUE faststep_cursor_explain(VALUE self) {
|
|
80
74
|
return result;
|
81
75
|
}
|
82
76
|
|
83
|
-
static VALUE faststep_cursor_skip(VALUE self, const VALUE skip_count) {
|
84
|
-
rb_iv_set(self, "@skip", skip_count);
|
85
|
-
return self;
|
86
|
-
}
|
87
|
-
|
88
|
-
static VALUE faststep_cursor_limit(VALUE self, const VALUE limit_count) {
|
89
|
-
rb_iv_set(self, "@limit", limit_count);
|
90
|
-
return self;
|
91
|
-
}
|
92
|
-
|
93
|
-
static VALUE faststep_cursor_fields(VALUE self, const VALUE fields) {
|
94
|
-
rb_iv_set(self, "@fields", fields);
|
95
|
-
return self;
|
96
|
-
}
|
97
|
-
|
98
77
|
static VALUE faststep_cursor_order(VALUE self, const VALUE order) {
|
99
78
|
rb_iv_set(self, "@order", ruby_array_to_bson_ordered_hash(order));
|
100
79
|
return self;
|
data/ext/faststep/cursor.h
CHANGED
@@ -13,9 +13,6 @@ static VALUE faststep_cursor_init(int, VALUE*, VALUE);
|
|
13
13
|
static VALUE faststep_cursor_new(int, VALUE*, VALUE);
|
14
14
|
static VALUE faststep_cursor_each(const VALUE);
|
15
15
|
static VALUE faststep_cursor_explain(VALUE);
|
16
|
-
static VALUE faststep_cursor_skip(VALUE, const VALUE);
|
17
|
-
static VALUE faststep_cursor_limit(VALUE, const VALUE);
|
18
|
-
static VALUE faststep_cursor_fields(VALUE, const VALUE);
|
19
16
|
static VALUE faststep_cursor_order(VALUE, const VALUE);
|
20
17
|
static mongo_cursor* _faststep_build_mongo_cursor(VALUE);
|
21
18
|
static VALUE _faststep_build_full_query(VALUE);
|
data/ext/faststep/db.c
CHANGED
@@ -9,24 +9,11 @@
|
|
9
9
|
void faststep_db_main() {
|
10
10
|
rb_cFaststepDb = rb_define_class_under(rb_mFaststep, "Db", rb_cObject);
|
11
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
12
|
rb_define_method(rb_cFaststepDb, "drop", faststep_db_drop, 0);
|
19
13
|
rb_define_method(rb_cFaststepDb, "command", faststep_db_command, 1);
|
20
14
|
rb_define_method(rb_cFaststepDb, "get_last_error", faststep_db_get_last_error, 0);
|
21
15
|
}
|
22
16
|
|
23
|
-
static VALUE faststep_db_init(VALUE self, VALUE name, VALUE connection) {
|
24
|
-
rb_iv_set(self, "@name", name);
|
25
|
-
rb_iv_set(self, "@connection", connection);
|
26
|
-
|
27
|
-
return self;
|
28
|
-
}
|
29
|
-
|
30
17
|
static VALUE faststep_db_drop(VALUE self) {
|
31
18
|
mongo_connection* conn = GetFaststepConnection(rb_iv_get(self, "@connection"));
|
32
19
|
|
data/ext/faststep/db.h
CHANGED
data/lib/faststep/collection.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module Faststep
|
2
2
|
class Collection
|
3
|
+
attr_reader :name, :db
|
4
|
+
|
5
|
+
def initialize(name, db)
|
6
|
+
@name = name
|
7
|
+
@db = db
|
8
|
+
end
|
9
|
+
|
10
|
+
def connection
|
11
|
+
db.connection
|
12
|
+
end
|
13
|
+
|
3
14
|
def index_information
|
4
15
|
info = {}
|
5
16
|
db["system.indexes"].find({:ns => ns}).each do |index|
|
@@ -9,7 +20,10 @@ module Faststep
|
|
9
20
|
end
|
10
21
|
|
11
22
|
def rename(new_name)
|
12
|
-
|
23
|
+
command = BSON::OrderedHash.new
|
24
|
+
command[:renameCollection] = ns
|
25
|
+
command[:to] = "#{db.name}.#{new_name}"
|
26
|
+
connection["admin"].command(command)
|
13
27
|
@name = new_name
|
14
28
|
true
|
15
29
|
end
|
data/lib/faststep/connection.rb
CHANGED
data/lib/faststep/cursor.rb
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
module Faststep
|
2
2
|
class Cursor
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :collection
|
6
|
+
|
7
|
+
def skip(count)
|
8
|
+
@skip = count
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def limit(count)
|
13
|
+
@limit = count
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def fields(field_array)
|
18
|
+
@fields = field_array
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
3
22
|
def to_a
|
4
23
|
super
|
5
24
|
end
|
data/lib/faststep/db.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
module Faststep
|
2
2
|
class Db
|
3
|
+
attr_reader :name, :connection
|
4
|
+
|
5
|
+
def initialize(name, connection)
|
6
|
+
@name = name
|
7
|
+
@connection = connection
|
8
|
+
end
|
9
|
+
|
3
10
|
def collection(collection_name)
|
4
11
|
Collection.new(collection_name, self)
|
5
12
|
end
|
6
13
|
|
14
|
+
alias [] collection
|
15
|
+
|
7
16
|
def collection_names
|
8
17
|
names = collections_info.map {|doc| doc["name"] }
|
9
18
|
names.reject! {|name| name.index(@name).nil? || name.index('$') }
|
data/lib/faststep/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: faststep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Josh Clayton
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-01 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake-compiler
|