tenacity 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/THANKS.md ADDED
@@ -0,0 +1,11 @@
1
+ Tenacity THANKS
2
+ ===============
3
+
4
+ Tenacity was originally developed by [John Wood](http://github.com/jwood). The
5
+ following people have contributed to the project by reporting problems,
6
+ suggesting improvements, or submitting changes.
7
+
8
+ * [danielgranat](http://github.com/danielgranat)
9
+
10
+ Patches are welcome. The primary source for this software project is [on Github](http://github.com/jwood/tenacity)
11
+
data/history.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.5.3
2
+
3
+ * Bug fixes
4
+
5
+ * Modified ORM extensions to use a default id type if the id type could not
6
+ be determined (was causing ActiveRecord migrations to fail)
7
+
1
8
  == 0.5.2
2
9
 
3
10
  * Bug fixes
@@ -6,9 +6,9 @@ module Tenacity
6
6
  associate_id = self.send(association.foreign_key)
7
7
  if associate_id != nil && associate_id.to_s.strip != ''
8
8
  if association.dependent == :destroy
9
- association.associate_class._t_delete(associate_id)
9
+ delete_or_destroy_belongs_to_associate(association, associate_id)
10
10
  elsif association.dependent == :delete
11
- association.associate_class._t_delete(associate_id, false)
11
+ delete_or_destroy_belongs_to_associate(association, associate_id, false)
12
12
  end
13
13
  end
14
14
  end
@@ -27,6 +27,10 @@ module Tenacity
27
27
  associate
28
28
  end
29
29
 
30
+ def delete_or_destroy_belongs_to_associate(association, associate_id, run_callbacks=true)
31
+ association.associate_class._t_delete(associate_id, run_callbacks)
32
+ end
33
+
30
34
  module ClassMethods #:nodoc:
31
35
  def initialize_belongs_to_association(association)
32
36
  _t_initialize_belongs_to_association(association) if self.respond_to?(:_t_initialize_belongs_to_association)
@@ -10,14 +10,11 @@ module Tenacity
10
10
  associates = has_many_associates(association)
11
11
  unless associates.nil? || associates.empty?
12
12
  if association.dependent == :destroy
13
- associates.each { |associate| association.associate_class._t_delete(_t_serialize(associate.id)) }
13
+ delete_or_destroy_has_many_associates(association, associates)
14
14
  elsif association.dependent == :delete_all
15
- associates.each { |associate| association.associate_class._t_delete(_t_serialize(associate.id), false) }
15
+ delete_or_destroy_has_many_associates(association, associates, false)
16
16
  elsif association.dependent == :nullify
17
- associates.each do |associate|
18
- associate.send "#{association.foreign_key(self.class)}=", nil
19
- associate._t_save_if_dirty
20
- end
17
+ nullify_foreign_keys_for_has_many_associates(association, associates)
21
18
  elsif association.foreign_key_constraints_enabled?
22
19
  raise ObjectIdInUseError.new("Unable to delete #{self.class} with id of #{self.id} because its id is being referenced by instances of #{associates.first.class}(id: #{associates.map(&:id).join(',')})!")
23
20
  end
@@ -77,6 +74,17 @@ module Tenacity
77
74
  end
78
75
  end
79
76
 
77
+ def delete_or_destroy_has_many_associates(association, associates, run_callbacks=true)
78
+ associates.each { |associate| association.associate_class._t_delete(_t_serialize(associate.id), run_callbacks) }
79
+ end
80
+
81
+ def nullify_foreign_keys_for_has_many_associates(association, associates)
82
+ associates.each do |associate|
83
+ associate.send "#{association.foreign_key(self.class)}=", nil
84
+ associate._t_save_if_dirty
85
+ end
86
+ end
87
+
80
88
  module ClassMethods #:nodoc:
81
89
  def initialize_has_many_association(association)
82
90
  _t_initialize_has_many_association(association) if self.respond_to?(:_t_initialize_has_many_association)
@@ -6,12 +6,11 @@ module Tenacity
6
6
  associate = has_one_associate(association)
7
7
  unless associate.nil?
8
8
  if association.dependent == :destroy
9
- association.associate_class._t_delete(_t_serialize(associate.id))
9
+ delete_or_destroy_has_one_associate(association, associate)
10
10
  elsif association.dependent == :delete
11
- association.associate_class._t_delete(_t_serialize(associate.id), false)
11
+ delete_or_destroy_has_one_associate(association, associate, false)
12
12
  elsif association.dependent == :nullify
13
- associate.send "#{association.foreign_key(self.class)}=", nil
14
- associate._t_save_if_dirty
13
+ nullify_foreign_key_for_has_one_associate(association, associate)
15
14
  elsif association.foreign_key_constraints_enabled?
16
15
  raise ObjectIdInUseError.new("Unable to delete #{self.class} with id of #{self.id} because its id is being referenced by an instance of #{associate.class}(id: #{associate.id})!")
17
16
  end
@@ -32,6 +31,15 @@ module Tenacity
32
31
  associate
33
32
  end
34
33
 
34
+ def delete_or_destroy_has_one_associate(association, associate, run_callbacks=true)
35
+ association.associate_class._t_delete(_t_serialize(associate.id), run_callbacks)
36
+ end
37
+
38
+ def nullify_foreign_key_for_has_one_associate(association, associate)
39
+ associate.send "#{association.foreign_key(self.class)}=", nil
40
+ associate._t_save_if_dirty
41
+ end
42
+
35
43
  module ClassMethods #:nodoc:
36
44
  def initialize_has_one_association(association)
37
45
  _t_initialize_has_one_association(association) if respond_to?(:_t_initialize_has_one_association)
@@ -6,17 +6,11 @@ module Tenacity
6
6
  end
7
7
 
8
8
  def _t_save_autosave_associations
9
- associations = self.class._tenacity_associations
10
- self.class._tenacity_associations.select { |a| a.autosave == true }.each do |association|
9
+ autosave_associations.each do |association|
11
10
  if association.type == :t_has_one || association.type == :t_belongs_to
12
- associate = instance_variable_get(_t_ivar_name(association))
13
- autosave_save_or_destroy(associate) unless associate.nil?
11
+ autosave_has_one_or_belongs_to(association)
14
12
  elsif association.type == :t_has_many
15
- associates = instance_variable_get(_t_ivar_name(association))
16
- unless associates.nil?
17
- associates.each { |associate| autosave_save_or_destroy(associate) }
18
- instance_variable_set(_t_ivar_name(association), associates.reject { |associate| associate.marked_for_destruction? })
19
- end
13
+ autosave_has_many(association)
20
14
  end
21
15
  end
22
16
  end
@@ -34,6 +28,23 @@ module Tenacity
34
28
 
35
29
  private
36
30
 
31
+ def autosave_associations
32
+ self.class._tenacity_associations.select { |a| a.autosave == true }
33
+ end
34
+
35
+ def autosave_has_one_or_belongs_to(association)
36
+ associate = instance_variable_get(_t_ivar_name(association))
37
+ autosave_save_or_destroy(associate) unless associate.nil?
38
+ end
39
+
40
+ def autosave_has_many(association)
41
+ associates = instance_variable_get(_t_ivar_name(association))
42
+ unless associates.nil?
43
+ associates.each { |associate| autosave_save_or_destroy(associate) }
44
+ instance_variable_set(_t_ivar_name(association), associates.reject { |associate| associate.marked_for_destruction? })
45
+ end
46
+ end
47
+
37
48
  def autosave_save_or_destroy(associate)
38
49
  associate.marked_for_destruction? ? autosave_destroy(associate) : associate._t_save_if_dirty
39
50
  end
@@ -49,7 +49,11 @@ module Tenacity
49
49
  include Tenacity::OrmExt::Helpers
50
50
 
51
51
  def _t_id_type
52
- @_t_id_type_clazz ||= Kernel.const_get(columns.find{ |x| x.primary }.type.to_s.capitalize)
52
+ @_t_id_type_clazz ||= begin
53
+ Kernel.const_get(columns.find{ |x| x.primary }.type.to_s.capitalize)
54
+ rescue
55
+ Integer
56
+ end
53
57
  end
54
58
 
55
59
  def _t_find(id)
@@ -49,7 +49,11 @@ module Tenacity
49
49
  include Tenacity::OrmExt::Helpers
50
50
 
51
51
  def _t_id_type
52
- @_t_id_type_clazz ||= properties.find{ |x| x.key? }.primitive
52
+ @_t_id_type_clazz ||= begin
53
+ properties.find{ |x| x.key? }.primitive
54
+ rescue
55
+ Integer
56
+ end
53
57
  end
54
58
 
55
59
  def _t_find(id)
@@ -232,10 +232,10 @@ module Tenacity
232
232
 
233
233
  def store_id_in_associate_index(associate_id, bucket)
234
234
  unless associate_id.nil?
235
- if bucket.exist?(associate_id)
235
+ begin
236
236
  object = bucket.get(associate_id)
237
237
  object.data << self.id unless object.data.include?(self.id)
238
- else
238
+ rescue Riak::FailedRequest
239
239
  object = bucket.new(associate_id)
240
240
  object.data = [self.id]
241
241
  end
@@ -55,7 +55,11 @@ module Tenacity
55
55
  attr_accessor :_t_belongs_to_associations
56
56
 
57
57
  def _t_id_type
58
- @_t_id_type_clazz ||= Kernel.const_get(db_schema.values.find{ |x| x[:primary_key] == true }[:type].to_s.capitalize)
58
+ @_t_id_type_clazz ||= begin
59
+ Kernel.const_get(db_schema.values.find{ |x| x[:primary_key] == true }[:type].to_s.capitalize)
60
+ rescue
61
+ Integer
62
+ end
59
63
  end
60
64
 
61
65
  def _t_find(id)
@@ -1,3 +1,3 @@
1
1
  module Tenacity
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -106,6 +106,9 @@ class ActiveRecordTest < Test::Unit::TestCase
106
106
  should "be able to successfully determine the id type" do
107
107
  assert_equal Integer, ActiveRecordObject._t_id_type
108
108
  assert_equal String, ActiveRecordObjectWithStringId._t_id_type
109
+
110
+ class ActiveRecordObjectWithNoTable < ActiveRecord::Base; include Tenacity; end
111
+ assert_equal Integer, ActiveRecordObjectWithNoTable._t_id_type
109
112
  end
110
113
  end
111
114
 
@@ -97,6 +97,9 @@ class DataMapperTest < Test::Unit::TestCase
97
97
  should "be able to successfully determine the id type" do
98
98
  assert_equal Integer, DataMapperObject._t_id_type
99
99
  assert_equal String, DataMapperObjectWithStringId._t_id_type
100
+
101
+ class DataMapperObjectWithNoTable; include DataMapper::Resource; include Tenacity; end
102
+ assert_equal Integer, DataMapperObjectWithNoTable._t_id_type
100
103
  end
101
104
 
102
105
  context "that works with t_has_many associations" do
@@ -107,6 +107,9 @@ class SequelTest < Test::Unit::TestCase
107
107
  should "be able to successfully determine the id type" do
108
108
  assert_equal Integer, SequelObject._t_id_type
109
109
  assert_equal String, SequelObjectWithStringId._t_id_type
110
+
111
+ class SequelObjectWithNoTable < Sequel::Model; include Tenacity; end
112
+ assert_equal Integer, SequelObjectWithNoTable._t_id_type
110
113
  end
111
114
  end
112
115
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenacity
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease:
5
- version: 0.5.2
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 3
10
+ version: 0.5.3
6
11
  platform: ruby
7
12
  authors:
8
13
  - John Wood
@@ -10,228 +15,327 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-07-15 00:00:00 -05:00
18
+ date: 2011-11-18 00:00:00 -06:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activesupport
23
+ prerelease: false
24
+ type: :runtime
18
25
  requirement: &id001 !ruby/object:Gem::Requirement
19
26
  none: false
20
27
  requirements:
21
28
  - - ">="
22
29
  - !ruby/object:Gem::Version
30
+ hash: 5
31
+ segments:
32
+ - 2
33
+ - 3
23
34
  version: "2.3"
24
- type: :runtime
25
- prerelease: false
26
35
  version_requirements: *id001
27
36
  - !ruby/object:Gem::Dependency
28
37
  name: bundler
38
+ prerelease: false
39
+ type: :development
29
40
  requirement: &id002 !ruby/object:Gem::Requirement
30
41
  none: false
31
42
  requirements:
32
43
  - - ~>
33
44
  - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
34
50
  version: 1.0.0
35
- type: :development
36
- prerelease: false
37
51
  version_requirements: *id002
38
52
  - !ruby/object:Gem::Dependency
39
53
  name: rake
54
+ prerelease: false
55
+ type: :development
40
56
  requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ~>
44
60
  - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 8
65
+ - 7
45
66
  version: 0.8.7
46
- type: :development
47
- prerelease: false
48
67
  version_requirements: *id003
49
68
  - !ruby/object:Gem::Dependency
50
69
  name: rcov
70
+ prerelease: false
71
+ type: :development
51
72
  requirement: &id004 !ruby/object:Gem::Requirement
52
73
  none: false
53
74
  requirements:
54
75
  - - ~>
55
76
  - !ruby/object:Gem::Version
77
+ hash: 41
78
+ segments:
79
+ - 0
80
+ - 9
81
+ - 9
56
82
  version: 0.9.9
57
- type: :development
58
- prerelease: false
59
83
  version_requirements: *id004
60
84
  - !ruby/object:Gem::Dependency
61
85
  name: shoulda
86
+ prerelease: false
87
+ type: :development
62
88
  requirement: &id005 !ruby/object:Gem::Requirement
63
89
  none: false
64
90
  requirements:
65
91
  - - ~>
66
92
  - !ruby/object:Gem::Version
93
+ hash: 37
94
+ segments:
95
+ - 2
96
+ - 11
97
+ - 3
67
98
  version: 2.11.3
68
- type: :development
69
- prerelease: false
70
99
  version_requirements: *id005
71
100
  - !ruby/object:Gem::Dependency
72
101
  name: mocha
102
+ prerelease: false
103
+ type: :development
73
104
  requirement: &id006 !ruby/object:Gem::Requirement
74
105
  none: false
75
106
  requirements:
76
107
  - - ~>
77
108
  - !ruby/object:Gem::Version
109
+ hash: 47
110
+ segments:
111
+ - 0
112
+ - 9
113
+ - 10
78
114
  version: 0.9.10
79
- type: :development
80
- prerelease: false
81
115
  version_requirements: *id006
82
116
  - !ruby/object:Gem::Dependency
83
117
  name: yard
118
+ prerelease: false
119
+ type: :development
84
120
  requirement: &id007 !ruby/object:Gem::Requirement
85
121
  none: false
86
122
  requirements:
87
123
  - - ~>
88
124
  - !ruby/object:Gem::Version
125
+ hash: 15
126
+ segments:
127
+ - 0
128
+ - 6
129
+ - 4
89
130
  version: 0.6.4
90
- type: :development
91
- prerelease: false
92
131
  version_requirements: *id007
93
132
  - !ruby/object:Gem::Dependency
94
133
  name: sqlite3-ruby
134
+ prerelease: false
135
+ type: :development
95
136
  requirement: &id008 !ruby/object:Gem::Requirement
96
137
  none: false
97
138
  requirements:
98
139
  - - ~>
99
140
  - !ruby/object:Gem::Version
141
+ hash: 25
142
+ segments:
143
+ - 1
144
+ - 3
145
+ - 1
100
146
  version: 1.3.1
101
- type: :development
102
- prerelease: false
103
147
  version_requirements: *id008
104
148
  - !ruby/object:Gem::Dependency
105
149
  name: activerecord
150
+ prerelease: false
151
+ type: :development
106
152
  requirement: &id009 !ruby/object:Gem::Requirement
107
153
  none: false
108
154
  requirements:
109
155
  - - ~>
110
156
  - !ruby/object:Gem::Version
157
+ hash: 7
158
+ segments:
159
+ - 3
160
+ - 0
161
+ - 0
111
162
  version: 3.0.0
112
- type: :development
113
- prerelease: false
114
163
  version_requirements: *id009
115
164
  - !ruby/object:Gem::Dependency
116
165
  name: datamapper
166
+ prerelease: false
167
+ type: :development
117
168
  requirement: &id010 !ruby/object:Gem::Requirement
118
169
  none: false
119
170
  requirements:
120
171
  - - ~>
121
172
  - !ruby/object:Gem::Version
173
+ hash: 19
174
+ segments:
175
+ - 1
176
+ - 0
177
+ - 2
122
178
  version: 1.0.2
123
- type: :development
124
- prerelease: false
125
179
  version_requirements: *id010
126
180
  - !ruby/object:Gem::Dependency
127
181
  name: dm-sqlite-adapter
182
+ prerelease: false
183
+ type: :development
128
184
  requirement: &id011 !ruby/object:Gem::Requirement
129
185
  none: false
130
186
  requirements:
131
187
  - - ~>
132
188
  - !ruby/object:Gem::Version
189
+ hash: 19
190
+ segments:
191
+ - 1
192
+ - 0
193
+ - 2
133
194
  version: 1.0.2
134
- type: :development
135
- prerelease: false
136
195
  version_requirements: *id011
137
196
  - !ruby/object:Gem::Dependency
138
197
  name: sequel
198
+ prerelease: false
199
+ type: :development
139
200
  requirement: &id012 !ruby/object:Gem::Requirement
140
201
  none: false
141
202
  requirements:
142
203
  - - ~>
143
204
  - !ruby/object:Gem::Version
205
+ hash: 75
206
+ segments:
207
+ - 3
208
+ - 19
209
+ - 0
144
210
  version: 3.19.0
145
- type: :development
146
- prerelease: false
147
211
  version_requirements: *id012
148
212
  - !ruby/object:Gem::Dependency
149
213
  name: mongo_mapper
214
+ prerelease: false
215
+ type: :development
150
216
  requirement: &id013 !ruby/object:Gem::Requirement
151
217
  none: false
152
218
  requirements:
153
219
  - - ~>
154
220
  - !ruby/object:Gem::Version
221
+ hash: 59
222
+ segments:
223
+ - 0
224
+ - 9
225
+ - 0
155
226
  version: 0.9.0
156
- type: :development
157
- prerelease: false
158
227
  version_requirements: *id013
159
228
  - !ruby/object:Gem::Dependency
160
229
  name: bson_ext
230
+ prerelease: false
231
+ type: :development
161
232
  requirement: &id014 !ruby/object:Gem::Requirement
162
233
  none: false
163
234
  requirements:
164
235
  - - ~>
165
236
  - !ruby/object:Gem::Version
237
+ hash: 27
238
+ segments:
239
+ - 1
240
+ - 3
241
+ - 0
166
242
  version: 1.3.0
167
- type: :development
168
- prerelease: false
169
243
  version_requirements: *id014
170
244
  - !ruby/object:Gem::Dependency
171
245
  name: mongoid
246
+ prerelease: false
247
+ type: :development
172
248
  requirement: &id015 !ruby/object:Gem::Requirement
173
249
  none: false
174
250
  requirements:
175
251
  - - ~>
176
252
  - !ruby/object:Gem::Version
253
+ hash: 15
254
+ segments:
255
+ - 2
256
+ - 0
257
+ - 0
177
258
  version: 2.0.0
178
- type: :development
179
- prerelease: false
180
259
  version_requirements: *id015
181
260
  - !ruby/object:Gem::Dependency
182
261
  name: couchrest
262
+ prerelease: false
263
+ type: :development
183
264
  requirement: &id016 !ruby/object:Gem::Requirement
184
265
  none: false
185
266
  requirements:
186
267
  - - ~>
187
268
  - !ruby/object:Gem::Version
269
+ hash: 23
270
+ segments:
271
+ - 1
272
+ - 0
273
+ - 0
188
274
  version: 1.0.0
189
- type: :development
190
- prerelease: false
191
275
  version_requirements: *id016
192
276
  - !ruby/object:Gem::Dependency
193
277
  name: couchrest_model
278
+ prerelease: false
279
+ type: :development
194
280
  requirement: &id017 !ruby/object:Gem::Requirement
195
281
  none: false
196
282
  requirements:
197
283
  - - ~>
198
284
  - !ruby/object:Gem::Version
285
+ hash: 23
286
+ segments:
287
+ - 1
288
+ - 0
289
+ - 0
199
290
  version: 1.0.0
200
- type: :development
201
- prerelease: false
202
291
  version_requirements: *id017
203
292
  - !ruby/object:Gem::Dependency
204
293
  name: ripple
294
+ prerelease: false
295
+ type: :development
205
296
  requirement: &id018 !ruby/object:Gem::Requirement
206
297
  none: false
207
298
  requirements:
208
299
  - - ~>
209
300
  - !ruby/object:Gem::Version
301
+ hash: 63
302
+ segments:
303
+ - 0
304
+ - 9
305
+ - 2
210
306
  version: 0.9.2
211
- type: :development
212
- prerelease: false
213
307
  version_requirements: *id018
214
308
  - !ruby/object:Gem::Dependency
215
309
  name: toystore
310
+ prerelease: false
311
+ type: :development
216
312
  requirement: &id019 !ruby/object:Gem::Requirement
217
313
  none: false
218
314
  requirements:
219
315
  - - ~>
220
316
  - !ruby/object:Gem::Version
317
+ hash: 63
318
+ segments:
319
+ - 0
320
+ - 8
321
+ - 0
221
322
  version: 0.8.0
222
- type: :development
223
- prerelease: false
224
323
  version_requirements: *id019
225
324
  - !ruby/object:Gem::Dependency
226
325
  name: adapter-mongo
326
+ prerelease: false
327
+ type: :development
227
328
  requirement: &id020 !ruby/object:Gem::Requirement
228
329
  none: false
229
330
  requirements:
230
331
  - - ~>
231
332
  - !ruby/object:Gem::Version
333
+ hash: 15
334
+ segments:
335
+ - 0
336
+ - 5
337
+ - 2
232
338
  version: 0.5.2
233
- type: :development
234
- prerelease: false
235
339
  version_requirements: *id020
236
340
  description: Tenacity provides a database client independent way of specifying simple relationships between models backed by different databases.
237
341
  email:
@@ -249,6 +353,7 @@ files:
249
353
  - LICENSE.txt
250
354
  - README.rdoc
251
355
  - Rakefile
356
+ - THANKS.md
252
357
  - history.txt
253
358
  - lib/tenacity.rb
254
359
  - lib/tenacity/associate_proxy.rb
@@ -355,7 +460,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
355
460
  requirements:
356
461
  - - ">="
357
462
  - !ruby/object:Gem::Version
358
- hash: -2063505334017830292
463
+ hash: 3
359
464
  segments:
360
465
  - 0
361
466
  version: "0"
@@ -364,6 +469,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
469
  requirements:
365
470
  - - ">="
366
471
  - !ruby/object:Gem::Version
472
+ hash: 23
473
+ segments:
474
+ - 1
475
+ - 3
476
+ - 6
367
477
  version: 1.3.6
368
478
  requirements: []
369
479