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.
Files changed (47) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +15 -0
  4. data/bench/standard_benchmark +178 -0
  5. data/ext/faststep/bson.c +687 -0
  6. data/ext/faststep/bson.h +225 -0
  7. data/ext/faststep/bson_ruby_conversion.c +44 -0
  8. data/ext/faststep/bson_ruby_conversion.h +10 -0
  9. data/ext/faststep/collection.c +187 -0
  10. data/ext/faststep/collection.h +24 -0
  11. data/ext/faststep/connection.c +85 -0
  12. data/ext/faststep/connection.h +17 -0
  13. data/ext/faststep/cursor.c +61 -0
  14. data/ext/faststep/cursor.h +10 -0
  15. data/ext/faststep/db.c +56 -0
  16. data/ext/faststep/db.h +8 -0
  17. data/ext/faststep/exceptions.c +7 -0
  18. data/ext/faststep/exceptions.h +5 -0
  19. data/ext/faststep/extconf.rb +3 -0
  20. data/ext/faststep/faststep.c +30 -0
  21. data/ext/faststep/faststep.h +4 -0
  22. data/ext/faststep/faststep_defines.h +11 -0
  23. data/ext/faststep/gridfs.c +799 -0
  24. data/ext/faststep/gridfs.h +278 -0
  25. data/ext/faststep/md5.c +381 -0
  26. data/ext/faststep/md5.h +91 -0
  27. data/ext/faststep/mongo.c +801 -0
  28. data/ext/faststep/mongo.h +188 -0
  29. data/ext/faststep/mongo_except.h +143 -0
  30. data/ext/faststep/numbers.c +127 -0
  31. data/ext/faststep/platform_hacks.h +93 -0
  32. data/ext/faststep/support.c +21 -0
  33. data/ext/faststep/support.h +6 -0
  34. data/faststep.gemspec +26 -0
  35. data/lib/faststep/collection.rb +21 -0
  36. data/lib/faststep/connection.rb +13 -0
  37. data/lib/faststep/cursor.rb +7 -0
  38. data/lib/faststep/db.rb +25 -0
  39. data/lib/faststep/version.rb +3 -0
  40. data/lib/faststep.rb +10 -0
  41. data/spec/collection_spec.rb +116 -0
  42. data/spec/connection_spec.rb +34 -0
  43. data/spec/cursor_spec.rb +24 -0
  44. data/spec/db_spec.rb +28 -0
  45. data/spec/spec_helper.rb +13 -0
  46. data/spec/support_spec.rb +14 -0
  47. metadata +181 -0
@@ -0,0 +1,25 @@
1
+ module Faststep
2
+ class Db
3
+ def collection(collection_name)
4
+ Collection.new(collection_name, self)
5
+ end
6
+
7
+ def collection_names
8
+ names = collections_info.map {|doc| doc["name"] }
9
+ names.reject! {|name| name.index(@name).nil? || name.index('$') }
10
+ names.map {|name| name.sub("#{@name}.", "") }
11
+ end
12
+
13
+ def collections
14
+ collection_names.map do |collection_name|
15
+ Collection.new(collection_name, self)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def collections_info
22
+ Cursor.new(Collection.new("system.namespaces", self), :selector => {}).to_a
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Faststep
2
+ VERSION = "0.0.1"
3
+ end
data/lib/faststep.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "bson"
2
+
3
+ module Faststep
4
+ autoload :Db, "faststep/db"
5
+ autoload :Connection, "faststep/connection"
6
+ autoload :Collection, "faststep/collection"
7
+ autoload :Cursor, "faststep/cursor"
8
+ end
9
+
10
+ require "faststep/faststep"
@@ -0,0 +1,116 @@
1
+ require "spec_helper"
2
+
3
+ describe Faststep::Collection do
4
+ let(:db) { $faststep_test_db }
5
+
6
+ it "inserts the correct documents" do
7
+ db["something"].insert(:foo => "bar")
8
+ db["another.thing"].insert(:baz => "qux")
9
+
10
+ db["something"].count(:foo => "bar").should == 1
11
+ db["something"].count(:baz => "qux").should == 0
12
+ db["another.thing"].count(:foo => "bar").should == 0
13
+ db["another.thing"].count(:foo => true).should == 0
14
+ db["another.thing"].count(:baz => "qux").should == 1
15
+ end
16
+
17
+ it "supports batch inserting" do
18
+ db["something"].insert([{:foo => "bar"}, {:baz => "qux"}])
19
+ db["something"].count.should == 2
20
+ db["something"].count(:foo => "bar").should == 1
21
+ end
22
+
23
+ it "finds documents" do
24
+ db["something"].insert(:foo => "bar")
25
+ db["another.thing"].insert(:baz => "qux")
26
+
27
+ db["something"].find({}).first["foo"].should == "bar"
28
+ db["another.thing"].find({}).first["baz"].should == "qux"
29
+ end
30
+
31
+ it "updates documents" do
32
+ db["something"].insert(:foo => "bar", :something => "fun")
33
+ db["something"].update({ :something => "fun" }, { "$set" => { :foo => "awesome" } })
34
+
35
+ db["something"].find({}).first["foo"].should == "awesome"
36
+ end
37
+
38
+ it "removes documents" do
39
+ db["something"].insert(5.times.map { {:foo => "bar", :something => "fun"} })
40
+ db["something"].insert(:foo => "bar", :baz => "what!")
41
+
42
+ db["something"].remove(:baz => "what!")
43
+ db["something"].count.should == 5
44
+ db["something"].remove
45
+ db["something"].count.should be_zero
46
+ end
47
+
48
+ it "drops collections" do
49
+ db["something"].insert(:foo => "bar")
50
+ db["something"].drop
51
+ db["something"].count.should be_zero
52
+ end
53
+ end
54
+
55
+ describe Faststep::Collection, "queries" do
56
+ let(:db) { $faststep_test_db }
57
+
58
+ before do
59
+ db["something"].insert(:foo => "bar")
60
+ db["something"].insert(:baz => "qux")
61
+ db["another.thing"].insert(:baz => "qux")
62
+ end
63
+
64
+ it "handles equality" do
65
+ db["something"].find(:foo => "bar").to_a.tap do |documents|
66
+ documents.length.should == 1
67
+ documents.first["foo"].should == "bar"
68
+ end
69
+ end
70
+
71
+ it "handles $in" do
72
+ db["something"].find(:foo => {"$in" => [nil, "bar"]}).to_a.tap do |documents|
73
+ documents.length.should == 2
74
+ documents.first["foo"].should == "bar"
75
+ end
76
+ end
77
+
78
+ it "handles regexes" do
79
+ db["something"].find(:baz => /q.[xyz]/).to_a.tap do |documents|
80
+ documents.length.should == 1
81
+ documents.first["baz"].should == "qux"
82
+ end
83
+ end
84
+ end
85
+
86
+ describe Faststep::Collection, "#insert" do
87
+ let(:large) {
88
+ {
89
+ 'base_url' => 'http://www.example.com/test-me',
90
+ 'total_word_count' => 6743,
91
+ 'access_time' => Time.now,
92
+ 'meta_tags' => {
93
+ 'description' => 'i am a long description string',
94
+ 'author' => 'Holly Man',
95
+ 'dynamically_created_meta_tag' => 'who know\n what'
96
+ },
97
+ 'page_structure' => {
98
+ 'counted_tags' => 3450,
99
+ 'no_of_js_attached' => 10,
100
+ 'no_of_images' => 6
101
+ },
102
+ 'harvested_words' => ['10gen','web','open','source','application','paas',
103
+ 'platform-as-a-service','technology','helps',
104
+ 'developers','focus','building','mongodb','mongo'] * 20
105
+ }
106
+ }
107
+
108
+ let(:db) { $faststep_test_db }
109
+ let(:document_count) { 50 }
110
+
111
+ it "batch inserts multiple large documents" do
112
+ db["something"].insert([large] * document_count)
113
+ db["something"].count.should == document_count
114
+ db["something"].count("base_url" => large["base_url"]).should == document_count
115
+ end
116
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe Faststep::Connection do
4
+ subject { Faststep::Connection.new("127.0.0.1", 27017) }
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
17
+
18
+ it "closes a connection to Mongo" do
19
+ subject.disconnect!
20
+ subject.should_not be_connected
21
+ subject.connect!
22
+ subject.should be_connected
23
+ end
24
+
25
+ it "connects to master by default" do
26
+ subject.should be_master
27
+ end
28
+ end
29
+
30
+ describe Faststep::Connection, "that doesn't connect due to misconfiguration" do
31
+ it "raises an exception" do
32
+ expect { Faststep::Connection.new("totally-bogus", 12345) }.to raise_error(Faststep::ConnectionFailure)
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Faststep::Cursor do
4
+ let(:collection) { $faststep_test_db["something"] }
5
+
6
+ it "finds documents" do
7
+ 10.times { collection.insert(:foo => "bar") }
8
+
9
+ collection.count.should == 10
10
+ cursor = Faststep::Cursor.new(collection, {})
11
+ cursor.to_a.length.should_not == 0
12
+ cursor.each do |doc|
13
+ doc[:foo].should == "bar"
14
+ end
15
+ end
16
+
17
+ it "caches documents" do
18
+ 10.times { collection.insert(:foo => "bar") }
19
+
20
+ cursor = Faststep::Cursor.new(collection, {})
21
+ cursor.to_a.length.should == 10
22
+ cursor.to_a.length.should == 10
23
+ end
24
+ end
data/spec/db_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Faststep::Db do
4
+ subject { $faststep_test_db }
5
+
6
+ it "knows its collection names" do
7
+ subject["something"].insert(:foo => "bar")
8
+ subject["another.thing"].insert(:baz => "qux")
9
+
10
+ subject.collection_names.should include("something", "another.thing")
11
+ subject.collection_names.should_not include(/$/)
12
+ end
13
+
14
+ it "runs specific commands" do
15
+ expect { subject.command(:dbstats => 1) }.to_not raise_error
16
+ expect { subject.command(:totally_bogus => 1) }.to raise_error(Faststep::OperationFailure)
17
+ end
18
+
19
+ it "drops the database" do
20
+ 2.times { subject["something"].insert(:foo => "bar") }
21
+ 2.times { subject["another.thing"].insert(:baz => "qux") }
22
+
23
+ subject.drop
24
+
25
+ subject["something"].count.should be_zero
26
+ subject["another.thing"].count.should be_zero
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require "rspec"
2
+ require "faststep"
3
+
4
+ $faststep_test_db = Faststep::Connection.new("127.0.0.1", 27017).db("faststep_test")
5
+
6
+ RSpec.configure do |config|
7
+ config.before do
8
+ $faststep_test_db.collections.each do |collection|
9
+ next if collection.name == 'system.indexes'
10
+ collection.drop
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Faststep::Support, "ok?" do
4
+ it "returns true when response is ok" do
5
+ Faststep::Support.ok?({ "ok" => true }).should be_true
6
+ Faststep::Support.ok?({ "ok" => 1.0 }).should be_true
7
+ end
8
+
9
+ it "returns false when response is not ok" do
10
+ Faststep::Support.ok?({ "ok" => false }).should be_false
11
+ Faststep::Support.ok?({ "ok" => 0.0 }).should be_false
12
+ Faststep::Support.ok?({ "ok" => nil }).should be_false
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faststep
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Josh Clayton
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-18 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake-compiler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 7
33
+ - 6
34
+ version: 0.7.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: bson
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 4
50
+ version: 1.2.4
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bson_ext
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 2
65
+ - 4
66
+ version: 1.2.4
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - "="
76
+ - !ruby/object:Gem::Version
77
+ hash: 27
78
+ segments:
79
+ - 2
80
+ - 5
81
+ - 0
82
+ version: 2.5.0
83
+ type: :development
84
+ version_requirements: *id004
85
+ description: Mongo on Speed
86
+ email:
87
+ - joshua.clayton@gmail.com
88
+ executables: []
89
+
90
+ extensions:
91
+ - ext/faststep/extconf.rb
92
+ extra_rdoc_files: []
93
+
94
+ files:
95
+ - .gitignore
96
+ - Gemfile
97
+ - Rakefile
98
+ - bench/standard_benchmark
99
+ - ext/faststep/bson.c
100
+ - ext/faststep/bson.h
101
+ - ext/faststep/bson_ruby_conversion.c
102
+ - ext/faststep/bson_ruby_conversion.h
103
+ - ext/faststep/collection.c
104
+ - ext/faststep/collection.h
105
+ - ext/faststep/connection.c
106
+ - ext/faststep/connection.h
107
+ - ext/faststep/cursor.c
108
+ - ext/faststep/cursor.h
109
+ - ext/faststep/db.c
110
+ - ext/faststep/db.h
111
+ - ext/faststep/exceptions.c
112
+ - ext/faststep/exceptions.h
113
+ - ext/faststep/extconf.rb
114
+ - ext/faststep/faststep.c
115
+ - ext/faststep/faststep.h
116
+ - ext/faststep/faststep_defines.h
117
+ - ext/faststep/gridfs.c
118
+ - ext/faststep/gridfs.h
119
+ - ext/faststep/md5.c
120
+ - ext/faststep/md5.h
121
+ - ext/faststep/mongo.c
122
+ - ext/faststep/mongo.h
123
+ - ext/faststep/mongo_except.h
124
+ - ext/faststep/numbers.c
125
+ - ext/faststep/platform_hacks.h
126
+ - ext/faststep/support.c
127
+ - ext/faststep/support.h
128
+ - faststep.gemspec
129
+ - lib/faststep.rb
130
+ - lib/faststep/collection.rb
131
+ - lib/faststep/connection.rb
132
+ - lib/faststep/cursor.rb
133
+ - lib/faststep/db.rb
134
+ - lib/faststep/version.rb
135
+ - spec/collection_spec.rb
136
+ - spec/connection_spec.rb
137
+ - spec/cursor_spec.rb
138
+ - spec/db_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support_spec.rb
141
+ has_rdoc: true
142
+ homepage:
143
+ licenses: []
144
+
145
+ post_install_message:
146
+ rdoc_options: []
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirements: []
169
+
170
+ rubyforge_project:
171
+ rubygems_version: 1.4.2
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: Mongo on Speed
175
+ test_files:
176
+ - spec/collection_spec.rb
177
+ - spec/connection_spec.rb
178
+ - spec/cursor_spec.rb
179
+ - spec/db_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/support_spec.rb