mingo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mingo/many_proxy.rb +5 -1
  2. data/lib/mingo.rb +23 -1
  3. metadata +4 -4
@@ -93,8 +93,12 @@ class Mingo
93
93
 
94
94
  def load_collection
95
95
  @collection ||= if @embedded.empty? then []
96
- else @model.find({:_id => {'$in' => self.object_ids}}, find_options)
96
+ else find_by_ids(self.object_ids)
97
97
  end
98
98
  end
99
+
100
+ def find_by_ids(ids)
101
+ @model.find_by_ids(ids, {}, find_options)
102
+ end
99
103
  end
100
104
  end
data/lib/mingo.rb CHANGED
@@ -59,8 +59,30 @@ class Mingo < Hashie::Dash
59
59
  collection.find(selector, {:convert => self}.update(options), &block)
60
60
  end
61
61
 
62
+ def find_by_ids(object_ids, query = {}, options = {})
63
+ find({:_id => {'$in' => object_ids}}.update(query), options)
64
+ end
65
+
66
+ def find_ordered_ids(object_ids, query = {}, options = {})
67
+ indexed = find_by_ids(object_ids, query, options).inject({}) do |hash, object|
68
+ hash[object.id] = object
69
+ hash
70
+ end
71
+
72
+ object_ids.map { |id| indexed[id] }
73
+ end
74
+
75
+ def paginate_ids(object_ids, paginate_options, options = {})
76
+ object_ids.paginate(paginate_options).tap do |collection|
77
+ collection.replace find_ordered_ids(collection, {}, options)
78
+ end
79
+ end
80
+
62
81
  def create(obj = nil)
63
- new(obj).tap { |doc| doc.save }
82
+ new(obj).tap do |object|
83
+ yield object if block_given?
84
+ object.save
85
+ end
64
86
  end
65
87
 
66
88
  def many(property, model, &block)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mislav Marohni\xC4\x87"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-12 00:00:00 +02:00
18
+ date: 2010-10-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency