kongo 1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/lib/kongo.rb +31 -4
- data/lib/kongo/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -81,7 +81,7 @@ class User < Model
|
|
81
81
|
Account::find_by_id(self['earnings_account'])
|
82
82
|
end
|
83
83
|
def spend
|
84
|
-
Account::find_by_id(
|
84
|
+
Account::find_by_id(self['spend_account'])
|
85
85
|
end
|
86
86
|
end
|
87
87
|
```
|
@@ -125,7 +125,8 @@ Instead, if we have the possibility of abstracting this into a library, we might
|
|
125
125
|
module Finance
|
126
126
|
|
127
127
|
# other finance functionality that does not belong directly to a
|
128
|
-
# model, eg something like
|
128
|
+
# model, eg. something like `Finance::convert_currency`
|
129
|
+
|
129
130
|
# our finance extensions to the models:
|
130
131
|
|
131
132
|
module Extensions
|
@@ -134,7 +135,7 @@ module Finance
|
|
134
135
|
Account::find_by_id(self['earnings_account'])
|
135
136
|
end
|
136
137
|
def spend
|
137
|
-
Account::find_by_id(
|
138
|
+
Account::find_by_id(self['spend_account'])
|
138
139
|
end
|
139
140
|
end
|
140
141
|
Kongo::Model.add_extension(:users, User)
|
data/lib/kongo.rb
CHANGED
@@ -106,7 +106,7 @@ module Kongo
|
|
106
106
|
|
107
107
|
# Inspecting a Mongo Model attempts to only show *useful* information,
|
108
108
|
# such as what its extensions are as well as certain ivars.
|
109
|
-
#
|
109
|
+
#
|
110
110
|
def inspect
|
111
111
|
proxy = Object.new
|
112
112
|
@visible_ivars.each do |ivar|
|
@@ -169,9 +169,9 @@ module Kongo
|
|
169
169
|
def each
|
170
170
|
@cursor.each { |e| yield Model.new(e, @coll) }
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
# `to_enum` returns an Enumerator which yields the results of the cursor.
|
174
|
-
#
|
174
|
+
#
|
175
175
|
def to_enum
|
176
176
|
Enumerator.new do |yielder|
|
177
177
|
while @cursor.has_next?
|
@@ -229,6 +229,33 @@ module Kongo
|
|
229
229
|
delta('$set', k => v)
|
230
230
|
end
|
231
231
|
|
232
|
+
# Default comparison is via the string version of the id.
|
233
|
+
#
|
234
|
+
# @example Compare two models.
|
235
|
+
# person <=> other_person
|
236
|
+
#
|
237
|
+
# @param [ Kongo::Model ] other The document to compare with.
|
238
|
+
#
|
239
|
+
# @return [ Integer ] -1, 0, 1.
|
240
|
+
#
|
241
|
+
def <=>(other)
|
242
|
+
self['_id'].to_s <=> other['_id'].to_s
|
243
|
+
end
|
244
|
+
|
245
|
+
# Performs equality checking on the document ids.
|
246
|
+
#
|
247
|
+
# @example Compare for equality.
|
248
|
+
# model == other
|
249
|
+
#
|
250
|
+
# @param [ Kongo::Model, Object ] other The other object to compare with.
|
251
|
+
#
|
252
|
+
# @return [ true, false ] True if the ids are equal, false if not.
|
253
|
+
#
|
254
|
+
def ==(other)
|
255
|
+
self.class == other.class &&
|
256
|
+
self['_id'] == other['_id']
|
257
|
+
end
|
258
|
+
|
232
259
|
# Add a delta
|
233
260
|
#
|
234
261
|
# delta '$inc',
|
@@ -313,7 +340,7 @@ module Kongo
|
|
313
340
|
|
314
341
|
# Inspecting a Mongo Model attempts to only show *useful* information,
|
315
342
|
# such as what its extensions are as well as certain ivars.
|
316
|
-
#
|
343
|
+
#
|
317
344
|
def inspect
|
318
345
|
proxy = Object.new
|
319
346
|
@visible_ivars.each do |ivar|
|
data/lib/kongo/version.rb
CHANGED