Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated to Mongo gems v0.20.1

  • Loading branch information...
commit 4804f585a77b589bf25f4f38ba2bfa307885d6d1 1 parent cab223e
Stephen Eley authored April 12, 2010
4  Rakefile
@@ -16,7 +16,9 @@ DESCRIPTION
16 16
     gem.email = "sfeley@gmail.com"
17 17
     gem.homepage = "http://github.com/SFEley/candy"
18 18
     gem.authors = ["Stephen Eley"]
19  
-    gem.add_dependency "mongo", ">= 0.19.1"
  19
+    gem.add_dependency "bson", ">= 0.20.1"
  20
+    gem.add_dependency "bson_ext", '>= 0.20.1'
  21
+    gem.add_dependency "mongo", ">= 0.20.1"
20 22
     gem.add_development_dependency "rspec", ">= 1.2.9"
21 23
     # gem.add_development_dependency "yard", ">= 0"
22 24
     gem.add_development_dependency "mocha", ">= 0.9.8"
2  lib/candy/crunch.rb
@@ -140,7 +140,7 @@ def index(property, direction=:asc)
140 140
         else
141 141
           raise TypeError, "Index direction should be :asc or :desc"
142 142
         end
143  
-        collection.create_index(property => mongo_direction)
  143
+        collection.create_index([[property, mongo_direction]])
144 144
       end
145 145
     end
146 146
     
17  lib/candy/wrapper.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'mongo'
  1
+require 'bson'
2 2
 require 'date'  # Only so we know what one is. Argh.
3 3
 require 'candy/qualified_const_get'
4 4
 
@@ -16,10 +16,10 @@ module Wrapper
16 16
                 Float, 
17 17
                 Time,
18 18
                 Regexp,
19  
-                ByteBuffer, 
20  
-                Mongo::ObjectID, 
21  
-                Mongo::Code,
22  
-                Mongo::DBRef]
  19
+                BSON::ByteBuffer, 
  20
+                BSON::ObjectID, 
  21
+                BSON::Code,
  22
+                BSON::DBRef]
23 23
     
24 24
     # Makes an object safe for the sharp pointy edges of MongoDB. Types properly serialized
25 25
     # by the BSON.serialize call get passed through unmolested; others are unpacked and their
@@ -28,8 +28,6 @@ def self.wrap(thing)
28 28
       # Pass the simple cases through
29 29
       return thing if BSON_SAFE.include?(thing.class)
30 30
       case thing
31  
-      # when Symbol
32  
-      #   wrap_symbol(thing)
33 31
       when Array
34 32
         wrap_array(thing)
35 33
       when Hash
@@ -71,11 +69,6 @@ def self.wrap_hash(hash)
71 69
       wrapped
72 70
     end
73 71
     
74  
-    # Returns a string that's distinctive enough for us to unwrap later and produce the same symbol.
75  
-    def self.wrap_symbol(symbol)
76  
-      "__:" + symbol.to_s
77  
-    end
78  
-    
79 72
     # Returns a nested hash containing the class and instance variables of the object.  It's not the
80 73
     # deepest we could ever go (it doesn't handle singleton methods, etc.) but it's a start.
81 74
     def self.wrap_object(object)
4  spec/candy/crunch_spec.rb
@@ -128,12 +128,12 @@ class PeanutBrittle
128 128
   describe "index" do
129 129
     it "can be created with just a property name" do
130 130
       PeanutBrittle.index(:blah)
131  
-      PeanutBrittle.collection.index_information.values[1].should == [["blah", Mongo::ASCENDING]]
  131
+      PeanutBrittle.collection.index_information.values[1]['key'].should == {"blah" => Mongo::ASCENDING}
132 132
     end
133 133
     
134 134
     it "can be created with a direction" do
135 135
       PeanutBrittle.index(:fwah, :desc)
136  
-      PeanutBrittle.collection.index_information.values[1].should == [["fwah", Mongo::DESCENDING]]
  136
+      PeanutBrittle.collection.index_information.values[1]['key'].should == {"fwah" => Mongo::DESCENDING}
137 137
     end
138 138
     
139 139
     it "throws an exception if you give it a type other than :asc or :desc" do
4  spec/candy/piece_spec.rb
@@ -21,7 +21,7 @@ class Nougat
21 21
   
22 22
   it "knows its ID after inserting" do
23 23
     @this.name = 'Zagnut'
24  
-    @this.id.should be_a(Mongo::ObjectID)
  24
+    @this.id.should be_a(BSON::ObjectID)
25 25
   end
26 26
   
27 27
   
@@ -112,7 +112,7 @@ class Nougat
112 112
     end
113 113
         
114 114
     it "returns nil on an object that can't be found" do
115  
-      id = Mongo::ObjectID.new
  115
+      id = BSON::ObjectID.new
116 116
       Zagnut(id).should be_nil
117 117
     end
118 118
     
6  spec/candy/wrapper_spec.rb
@@ -50,7 +50,7 @@ def explode
50 50
       end
51 51
   
52 52
       it "can wrap an ObjectID" do
53  
-        i = Mongo::ObjectID.new
  53
+        i = BSON::ObjectID.new
54 54
         Wrapper.wrap(i).should == i
55 55
       end
56 56
 
@@ -65,12 +65,12 @@ def explode
65 65
       end
66 66
   
67 67
       it "can wrap a Mongo code object (if we ever need to)" do
68  
-        c = Mongo::Code.new('5')
  68
+        c = BSON::Code.new('5')
69 69
         Wrapper.wrap(c).should == c
70 70
       end
71 71
   
72 72
       it "can wrap a Mongo DBRef (if we ever need to)" do
73  
-        d = Mongo::DBRef.new('foo', Mongo::ObjectID.new)
  73
+        d = BSON::DBRef.new('foo', BSON::ObjectID.new)
74 74
         Wrapper.wrap(d).should == d
75 75
       end
76 76
   

0 notes on commit 4804f58

Please sign in to comment.
Something went wrong with that request. Please try again.