tenacity 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.gitignore +3 -0
  2. data/EXTEND.rdoc +11 -1
  3. data/README.rdoc +4 -1
  4. data/Rakefile +20 -9
  5. data/history.txt +21 -0
  6. data/lib/tenacity.rb +12 -4
  7. data/lib/tenacity/associates_proxy.rb +67 -0
  8. data/lib/tenacity/association.rb +19 -6
  9. data/lib/tenacity/associations/has_many.rb +6 -0
  10. data/lib/tenacity/class_methods.rb +52 -1
  11. data/lib/tenacity/instance_methods.rb +7 -3
  12. data/lib/tenacity/orm_ext/activerecord.rb +30 -13
  13. data/lib/tenacity/orm_ext/couchrest.rb +140 -0
  14. data/lib/tenacity/orm_ext/datamapper.rb +139 -0
  15. data/lib/tenacity/orm_ext/mongo_mapper.rb +88 -80
  16. data/lib/tenacity/orm_ext/mongoid.rb +108 -0
  17. data/lib/tenacity/orm_ext/sequel.rb +134 -0
  18. data/lib/tenacity/version.rb +1 -1
  19. data/tenacity.gemspec +14 -3
  20. data/test/association_features/belongs_to_test.rb +42 -0
  21. data/test/association_features/has_many_test.rb +110 -0
  22. data/test/association_features/has_one_test.rb +41 -0
  23. data/test/associations/belongs_to_test.rb +36 -127
  24. data/test/associations/has_many_test.rb +77 -196
  25. data/test/associations/has_one_test.rb +22 -84
  26. data/test/core/classmethods_test.rb +24 -22
  27. data/test/fixtures/active_record_has_many_target.rb +10 -0
  28. data/test/fixtures/active_record_has_one_target.rb +10 -0
  29. data/test/fixtures/{active_record_nuts.rb → active_record_nut.rb} +0 -0
  30. data/test/fixtures/active_record_object.rb +17 -0
  31. data/test/fixtures/couch_rest_door.rb +0 -2
  32. data/test/fixtures/couch_rest_has_many_target.rb +12 -0
  33. data/test/fixtures/couch_rest_has_one_target.rb +12 -0
  34. data/test/fixtures/couch_rest_object.rb +19 -0
  35. data/test/fixtures/couch_rest_windshield.rb +0 -2
  36. data/test/fixtures/data_mapper_has_many_target.rb +19 -0
  37. data/test/fixtures/data_mapper_has_one_target.rb +19 -0
  38. data/test/fixtures/data_mapper_object.rb +20 -0
  39. data/test/fixtures/mongo_mapper_ash_tray.rb +0 -2
  40. data/test/fixtures/mongo_mapper_dashboard.rb +0 -2
  41. data/test/fixtures/mongo_mapper_has_many_target.rb +11 -0
  42. data/test/fixtures/mongo_mapper_has_one_target.rb +11 -0
  43. data/test/fixtures/mongo_mapper_object.rb +18 -0
  44. data/test/fixtures/mongo_mapper_vent.rb +0 -2
  45. data/test/fixtures/mongo_mapper_wheel.rb +0 -2
  46. data/test/fixtures/mongoid_has_many_target.rb +13 -0
  47. data/test/fixtures/mongoid_has_one_target.rb +13 -0
  48. data/test/fixtures/mongoid_object.rb +20 -0
  49. data/test/fixtures/sequel_has_many_target.rb +10 -0
  50. data/test/fixtures/sequel_has_one_target.rb +10 -0
  51. data/test/fixtures/sequel_object.rb +17 -0
  52. data/test/helpers/active_record_test_helper.rb +51 -0
  53. data/test/helpers/data_mapper_test_helper.rb +44 -0
  54. data/test/helpers/mongoid_test_helper.rb +21 -0
  55. data/test/helpers/sequel_test_helper.rb +60 -0
  56. data/test/orm_ext/activerecord_test.rb +55 -35
  57. data/test/orm_ext/couchrest_test.rb +66 -46
  58. data/test/orm_ext/datamapper_test.rb +112 -0
  59. data/test/orm_ext/mongo_mapper_test.rb +64 -44
  60. data/test/orm_ext/mongoid_test.rb +121 -0
  61. data/test/orm_ext/sequel_test.rb +113 -0
  62. data/test/test_helper.rb +87 -11
  63. metadata +159 -59
  64. data/lib/tenacity/orm_ext/couchrest/couchrest_extended_document.rb +0 -42
  65. data/lib/tenacity/orm_ext/couchrest/couchrest_model.rb +0 -44
  66. data/lib/tenacity/orm_ext/couchrest/tenacity_class_methods.rb +0 -43
  67. data/lib/tenacity/orm_ext/couchrest/tenacity_instance_methods.rb +0 -21
  68. data/test/fixtures/couch_rest_radio.rb +0 -10
  69. data/test/fixtures/mongo_mapper_button.rb +0 -6
@@ -1,43 +0,0 @@
1
- module CouchRest
2
- module TenacityClassMethods #:nodoc:
3
- def _t_find(id)
4
- get(id)
5
- end
6
-
7
- def _t_find_bulk(ids)
8
- return [] if ids.nil? || ids.empty?
9
-
10
- docs = []
11
- result = database.get_bulk ids
12
- result['rows'].each do |row|
13
- docs << (row['doc'].nil? ? nil : create_from_database(row['doc']))
14
- end
15
- docs.reject { |doc| doc.nil? }
16
- end
17
-
18
- def _t_find_first_by_associate(property, id)
19
- self.send("by_#{property}", :key => id.to_s).first
20
- end
21
-
22
- def _t_find_all_by_associate(property, id)
23
- self.send("by_#{property}", :key => id.to_s)
24
- end
25
-
26
- def _t_initialize_has_many_association(association)
27
- unless self.respond_to?(association.foreign_keys_property)
28
- property association.foreign_keys_property, :type => [String]
29
- view_by association.foreign_keys_property
30
- after_save { |record| record.class._t_save_associates(record, association) if record.class.respond_to?(:_t_save_associates) }
31
- end
32
- end
33
-
34
- def _t_initialize_belongs_to_association(association)
35
- property_name = association.foreign_key
36
- unless self.respond_to?(property_name)
37
- property property_name, :type => String
38
- view_by property_name
39
- before_save { |record| _t_stringify_belongs_to_value(record, association) if self.respond_to?(:_t_stringify_belongs_to_value) }
40
- end
41
- end
42
- end
43
- end
@@ -1,21 +0,0 @@
1
- module CouchRest
2
- module TenacityInstanceMethods #:nodoc:
3
- def _t_reload
4
- new_doc = database.get(self.id)
5
- self.clear
6
- new_doc.each { |k,v| self[k] = new_doc[k] }
7
- end
8
-
9
- def _t_associate_many(association, associate_ids)
10
- self.send(association.foreign_keys_property + '=', associate_ids.map { |associate_id| associate_id.to_s })
11
- end
12
-
13
- def _t_get_associate_ids(association)
14
- self.send(association.foreign_keys_property) || []
15
- end
16
-
17
- def _t_clear_associates(association)
18
- self.send(association.foreign_keys_property + '=', [])
19
- end
20
- end
21
- end
@@ -1,10 +0,0 @@
1
- require 'couchrest_model'
2
-
3
- class CouchRestRadio < CouchRest::Model::Base
4
- include Tenacity
5
- use_database COUCH_DB
6
-
7
- t_belongs_to :mongo_mapper_dashboard
8
- t_has_many :mongo_mapper_buttons
9
- end
10
-
@@ -1,6 +0,0 @@
1
- class MongoMapperButton
2
- include MongoMapper::Document
3
- include Tenacity
4
-
5
- t_belongs_to :couch_rest_radio
6
- end