mordor 0.2.19 → 0.2.20

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/mordor/resource.rb +40 -5
  2. data/mordor.gemspec +2 -2
  3. metadata +28 -28
@@ -81,8 +81,10 @@ module Mordor
81
81
  end
82
82
  self_hash = ordered_self_hash
83
83
  end
84
- insert_id = self.class.collection.insert(self_hash)
85
- self._id = insert_id
84
+ with_collection do |collection|
85
+ insert_id = collection.insert(self_hash)
86
+ self._id = insert_id
87
+ end
86
88
  else
87
89
  insert_id = self.update
88
90
  end
@@ -91,8 +93,17 @@ module Mordor
91
93
 
92
94
  alias_method :save!, :save
93
95
 
96
+ def with_collection
97
+ self.class.with_collection do |collection|
98
+ yield collection
99
+ end
100
+ end
101
+
94
102
  def update
95
- insert_id = self.class.collection.update({:_id => self._id}, self.to_hash)
103
+ insert_id = nil
104
+ with_collection do |collection|
105
+ insert_id = collection.update({:_id => self._id}, self.to_hash)
106
+ end
96
107
  insert_id
97
108
  end
98
109
 
@@ -136,7 +147,11 @@ module Mordor
136
147
  end
137
148
 
138
149
  def collection
139
- database.collection(self.collection_name)
150
+ collection = nil
151
+ with_database do |database|
152
+ collection = database.collection(self.collection_name)
153
+ end
154
+ collection
140
155
  end
141
156
 
142
157
  def collection_name
@@ -171,6 +186,24 @@ module Mordor
171
186
  @db
172
187
  end
173
188
 
189
+ def with_database(max_retries=60)
190
+ retries = 0
191
+ begin
192
+ yield self.database
193
+ rescue Mongo::ConnectionFailure => ex
194
+ retries += 1
195
+ raise ex if retries > max_retries
196
+ sleep(0.5)
197
+ retry
198
+ end
199
+ end
200
+
201
+ def with_collection
202
+ with_database do |database|
203
+ yield database.collection(self.collection_name)
204
+ end
205
+ end
206
+
174
207
  def find_by_id(id)
175
208
  get(id)
176
209
  end
@@ -250,7 +283,9 @@ module Mordor
250
283
  end
251
284
 
252
285
  def ensure_index(attribute)
253
- collection.ensure_index( [ [attribute.to_s, index_types[attribute] ]] )
286
+ with_collection do |collection|
287
+ collection.ensure_index( [ [attribute.to_s, index_types[attribute] ]] )
288
+ end
254
289
  end
255
290
 
256
291
  def indices
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
2
2
  s.name = "mordor"
3
3
 
4
4
  # Do not set the version and date field manually, this is done by the release script
5
- s.version = "0.2.19"
6
- s.date = "2013-01-23"
5
+ s.version = "0.2.20"
6
+ s.date = "2013-06-10"
7
7
 
8
8
  s.summary = "mordor"
9
9
  s.description = <<-eos
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mordor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 19
10
- version: 0.2.19
9
+ - 20
10
+ version: 0.2.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan-Willem Koelewijn
@@ -16,12 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-01-23 00:00:00 +01:00
19
+ date: 2013-06-10 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- type: :development
24
- prerelease: false
23
+ name: rake
25
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -31,11 +30,11 @@ dependencies:
31
30
  segments:
32
31
  - 0
33
32
  version: "0"
34
- name: rake
33
+ prerelease: false
34
+ type: :development
35
35
  requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- type: :development
38
- prerelease: false
37
+ name: rspec
39
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
@@ -46,11 +45,11 @@ dependencies:
46
45
  - 2
47
46
  - 0
48
47
  version: "2.0"
49
- name: rspec
48
+ prerelease: false
49
+ type: :development
50
50
  requirement: *id002
51
51
  - !ruby/object:Gem::Dependency
52
- type: :development
53
- prerelease: false
52
+ name: json
54
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
55
54
  none: false
56
55
  requirements:
@@ -60,11 +59,11 @@ dependencies:
60
59
  segments:
61
60
  - 0
62
61
  version: "0"
63
- name: json
62
+ prerelease: false
63
+ type: :development
64
64
  requirement: *id003
65
65
  - !ruby/object:Gem::Dependency
66
- type: :development
67
- prerelease: false
66
+ name: extlib
68
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
69
68
  none: false
70
69
  requirements:
@@ -74,11 +73,11 @@ dependencies:
74
73
  segments:
75
74
  - 0
76
75
  version: "0"
77
- name: extlib
76
+ prerelease: false
77
+ type: :development
78
78
  requirement: *id004
79
79
  - !ruby/object:Gem::Dependency
80
- type: :development
81
- prerelease: false
80
+ name: mongo
82
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
83
82
  none: false
84
83
  requirements:
@@ -88,11 +87,11 @@ dependencies:
88
87
  segments:
89
88
  - 0
90
89
  version: "0"
91
- name: mongo
90
+ prerelease: false
91
+ type: :development
92
92
  requirement: *id005
93
93
  - !ruby/object:Gem::Dependency
94
- type: :runtime
95
- prerelease: false
94
+ name: extlib
96
95
  version_requirements: &id006 !ruby/object:Gem::Requirement
97
96
  none: false
98
97
  requirements:
@@ -102,11 +101,11 @@ dependencies:
102
101
  segments:
103
102
  - 0
104
103
  version: "0"
105
- name: extlib
104
+ prerelease: false
105
+ type: :runtime
106
106
  requirement: *id006
107
107
  - !ruby/object:Gem::Dependency
108
- type: :runtime
109
- prerelease: false
108
+ name: mongo
110
109
  version_requirements: &id007 !ruby/object:Gem::Requirement
111
110
  none: false
112
111
  requirements:
@@ -116,11 +115,11 @@ dependencies:
116
115
  segments:
117
116
  - 0
118
117
  version: "0"
119
- name: mongo
118
+ prerelease: false
119
+ type: :runtime
120
120
  requirement: *id007
121
121
  - !ruby/object:Gem::Dependency
122
- type: :runtime
123
- prerelease: false
122
+ name: json
124
123
  version_requirements: &id008 !ruby/object:Gem::Requirement
125
124
  none: false
126
125
  requirements:
@@ -130,7 +129,8 @@ dependencies:
130
129
  segments:
131
130
  - 0
132
131
  version: "0"
133
- name: json
132
+ prerelease: false
133
+ type: :runtime
134
134
  requirement: *id008
135
135
  description: " Small gem to add MongoDB Resources, resources have attributes that translate into document fields. When an attribute is declared, finders for the attribute are added to the Resource automatically\n"
136
136
  email: