faststep 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -12,7 +12,11 @@ Add to your Gemfile and `bundle`; otherwise,
12
12
 
13
13
  Connect to mongo:
14
14
 
15
- >> conn = Faststep::Connection.new("127.0.0.1", 27017)
15
+ >> conn = Faststep::Connection.new # defaults to 127.0.0.1:27017
16
+
17
+ Or connect to a custom host and port:
18
+
19
+ >> conn = Faststep::Connection.new("custom.host", 12345)
16
20
 
17
21
  Pick a database:
18
22
 
@@ -9,19 +9,28 @@ void faststep_connection_main() {
9
9
  rb_define_attr(rb_cFaststepConnection, "host", 1, 0);
10
10
  rb_define_attr(rb_cFaststepConnection, "port", 1, 0);
11
11
 
12
- rb_define_singleton_method(rb_cFaststepConnection, "new", faststep_connection_new, 2);
12
+ rb_define_singleton_method(rb_cFaststepConnection, "new", faststep_connection_new, -1);
13
13
 
14
- rb_define_method(rb_cFaststepConnection, "initialize", faststep_connection_init, 2);
14
+ rb_define_method(rb_cFaststepConnection, "initialize", faststep_connection_init, -1);
15
15
  rb_define_method(rb_cFaststepConnection, "connect!", faststep_connection_connect, 0);
16
16
  rb_define_method(rb_cFaststepConnection, "disconnect!", faststep_connection_disconnect, 0);
17
17
  rb_define_method(rb_cFaststepConnection, "connected?", faststep_connection_connected, 0);
18
18
  rb_define_method(rb_cFaststepConnection, "master?", faststep_connection_master, 0);
19
19
  rb_define_method(rb_cFaststepConnection, "db", faststep_connection_db, 1);
20
20
 
21
+ rb_define_alias(rb_cFaststepConnection, "[]", "db");
22
+
21
23
  return;
22
24
  }
23
25
 
24
- static VALUE faststep_connection_init(VALUE self, const VALUE host, const VALUE port) {
26
+ static VALUE faststep_connection_init(int argc, VALUE* argv, VALUE self) {
27
+ VALUE host, port;
28
+
29
+ rb_scan_args(argc, argv, "02", &host, &port);
30
+
31
+ if(!RTEST(host)) { host = rb_str_new2("127.0.0.1"); }
32
+ if(!RTEST(port)) { port = INT2NUM(27017); }
33
+
25
34
  rb_iv_set(self, "@host", host);
26
35
  rb_iv_set(self, "@port", port);
27
36
 
@@ -30,16 +39,12 @@ static VALUE faststep_connection_init(VALUE self, const VALUE host, const VALUE
30
39
  return self;
31
40
  }
32
41
 
33
- static VALUE faststep_connection_new(VALUE class, const VALUE host, const VALUE port) {
42
+ static VALUE faststep_connection_new(int argc, VALUE* argv, VALUE class) {
34
43
  mongo_connection* conn = (mongo_connection*)bson_malloc(sizeof(mongo_connection));
35
44
 
36
45
  VALUE tdata = Data_Wrap_Struct(class, NULL, mongo_destroy, conn);
37
46
 
38
- VALUE argv[2];
39
- argv[0] = host;
40
- argv[1] = port;
41
-
42
- rb_obj_call_init(tdata, 2, argv);
47
+ rb_obj_call_init(tdata, argc, argv);
43
48
 
44
49
  return tdata;
45
50
  }
@@ -4,8 +4,8 @@
4
4
  #define CONNECTION_H
5
5
  void faststep_connection_main();
6
6
 
7
- static VALUE faststep_connection_init(VALUE, const VALUE, const VALUE);
8
- static VALUE faststep_connection_new(VALUE, const VALUE, const VALUE);
7
+ static VALUE faststep_connection_init(int, VALUE*, VALUE);
8
+ static VALUE faststep_connection_new(int, VALUE*, VALUE);
9
9
  static VALUE faststep_connection_connect(VALUE);
10
10
  static VALUE faststep_connection_disconnect(const VALUE);
11
11
  static VALUE faststep_connection_connected(const VALUE);
@@ -1,3 +1,3 @@
1
1
  module Faststep
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,17 +3,10 @@ require "spec_helper"
3
3
  describe Faststep::Connection do
4
4
  subject { Faststep::Connection.new("127.0.0.1", 27017) }
5
5
 
6
- it "knows its host" do
7
- subject.host == "127.0.0.1"
8
- end
9
-
10
- it "knows its port" do
11
- subject.port == 27017
12
- end
13
-
14
- it "connects to Mongo automatically" do
15
- subject.should be_connected
16
- end
6
+ its(:host) { should == "127.0.0.1" }
7
+ its(:port) { should == 27017 }
8
+ it { should be_connected }
9
+ it { should be_master }
17
10
 
18
11
  it "closes a connection to Mongo" do
19
12
  subject.disconnect!
@@ -21,9 +14,22 @@ describe Faststep::Connection do
21
14
  subject.connect!
22
15
  subject.should be_connected
23
16
  end
17
+ end
18
+
19
+ describe Faststep::Connection, "host and port defaults" do
20
+ subject { Faststep::Connection.new }
21
+ its(:host) { should == "127.0.0.1" }
22
+ its(:port) { should == 27017 }
23
+ it { should be_connected }
24
+ it { should be_master }
25
+ end
26
+
27
+ describe Faststep::Connection, "getting a database" do
28
+ subject { Faststep::Connection.new }
24
29
 
25
- it "connects to master by default" do
26
- subject.should be_master
30
+ it "uses a database" do
31
+ subject[$faststep_test_db.name]["something"].insert(:foo => "bar")
32
+ $faststep_test_db["something"].count.should == 1
27
33
  end
28
34
  end
29
35
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: faststep
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
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-03-25 00:00:00 -04:00
13
+ date: 2011-04-18 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency