mongo_odm 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -164,7 +164,7 @@ To embed just one copy of another class, just define the field type of that clas
164
164
  index :name, :unique => true
165
165
  end
166
166
 
167
- Color.create_indexes
167
+ Color.create_indexes # You can also use MongoODM.create_indexes to create all the indexes at all classes at the same time
168
168
 
169
169
  color = Color.new(:name => "red", :rgb => RGB.new(255,0,0))
170
170
  color.save
@@ -51,5 +51,17 @@ module MongoODM
51
51
  def self.dereference(value)
52
52
  value.respond_to?(:dereference) ? value.dereference : value
53
53
  end
54
+
55
+ def self.indexed_classes
56
+ @_indexes ||= Set.new
57
+ end
58
+
59
+ def self.create_indexes
60
+ indexed_classes.each {|klass| klass.create_indexes}
61
+ end
62
+
63
+ def self.add_index_class(klass)
64
+ indexed_classes << klass
65
+ end
54
66
 
55
67
  end
@@ -287,4 +287,20 @@ class NilClass
287
287
  def to_mongo
288
288
  nil
289
289
  end
290
+ end
291
+
292
+ # @private
293
+ class Set
294
+ def self.type_cast(value)
295
+ return nil if value.nil?
296
+ Set.new(Array.type_cast(value))
297
+ end
298
+
299
+ def to_mongo
300
+ self.map {|elem| elem.to_mongo}
301
+ end
302
+
303
+ def dereference
304
+ MongoODM.instanciate(self.map{|value| MongoODM.dereference(value)})
305
+ end
290
306
  end
@@ -38,6 +38,7 @@ module MongoODM
38
38
  def index(spec, opts = {})
39
39
  new_index = Index.new(spec, opts)
40
40
  indexes << new_index
41
+ MongoODM.add_index_class(self)
41
42
  new_index
42
43
  end
43
44
 
@@ -2,6 +2,6 @@
2
2
  module MongoODM
3
3
  VERSION_MAJOR = "0"
4
4
  VERSION_MINOR = "2"
5
- VERSION_BUILD = "16"
5
+ VERSION_BUILD = "17"
6
6
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_BUILD}"
7
7
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongo_odm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.16
5
+ version: 0.2.17
6
6
  platform: ruby
7
7
  authors:
8
8
  - Carlos Paramio
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-20 00:00:00 +01:00
13
+ date: 2011-03-30 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency