tenacity 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tenacity (0.1.0)
4
+ tenacity (0.1.1)
5
5
  activesupport (>= 2.3)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -4,9 +4,9 @@ An ORM independent way of specifying simple relationships between models
4
4
  backed by different databases.
5
5
 
6
6
  It is sometimes necessary, or advantageous, to use more than one database in a
7
- given application. However, most ORMs do not support inter-database
8
- relationships. While supporting such relationships isn't difficult, it can
9
- add quite a bit of boilerplate code to your project.
7
+ given application (polyglot persistence). However, most ORMs do not support
8
+ inter-database relationships. While supporting such relationships isn't difficult,
9
+ it can add quite a bit of boilerplate code to your project.
10
10
 
11
11
  Tenacity aims to address this by providing an ORM independent way of specifying
12
12
  simple relationships between models backed by different databases.
@@ -17,33 +17,61 @@ much the same way, supporting many of the same options.
17
17
 
18
18
  == Example
19
19
 
20
- class User
20
+ class Car
21
21
  include MongoMapper::Document
22
22
  include Tenacity
23
23
 
24
- t_has_many :entries
24
+ t_has_many :wheels
25
+ t_has_one :dashboard
25
26
  end
26
27
 
27
- class Entry < ActiveRecord::Base
28
+ class Wheel < ActiveRecord::Base
28
29
  include Tenacity
29
30
 
30
- t_belongs_to :user
31
+ t_belongs_to :car
31
32
  end
32
33
 
34
+ class Dashboard < CouchRest::ExtendedDocument
35
+ include Tenacity
36
+ use_database MY_COUCHDB_DATABASE
33
37
 
34
- # Fetch related object from the respective database
35
- entry.user
38
+ t_belongs_to :car
39
+ end
40
+
41
+ car = Car.create
36
42
 
37
43
  # Set the related object
38
- entry.user = some_user
39
- entry.save
44
+ dashboard = Dashboard.create({})
45
+ car.dashboard = dashboard
46
+ car.save
47
+
48
+ # Fetch related object from the respective database
49
+ car.dashboard
40
50
 
41
- # Fetch related objects from the respective database
42
- user.entries
51
+ # Fetch related object id
52
+ car.dashboard.car_id
53
+
54
+ # Set related objects
55
+ wheel_1 = Wheel.create
56
+ wheel_2 = Wheel.create
57
+ wheel_3 = Wheel.create
58
+ wheels = [wheel_1, wheel_2, wheel_3]
59
+ car.wheels = wheels
60
+ car.save
61
+
62
+ wheel_1.car_id # car.id
63
+
64
+ # Fetch array of related objects from the respective database
65
+ car.wheels # [wheel_1, wheel_2, wheel_3]
66
+
67
+ # Fetch ids of related objects from the database
68
+ car.wheel_ids # [wheel_1.id, wheel_2.id, wheel_3.id]
43
69
 
44
70
  # Add a related object to the collection
45
- user.entries << some_entry
46
- user.save
71
+ new_wheel = Wheel.create
72
+ car.wheels << new_wheel
73
+ car.save
74
+ car.wheels # [wheel_1, wheel_2, wheel_3, wheel_4]
47
75
 
48
76
 
49
77
  == Additional Usage Details
@@ -82,13 +110,9 @@ See EXTEND.rdoc for information on extendeding Tenacity to work with other ORMs.
82
110
 
83
111
  bundler install
84
112
 
85
- * Create the test databases
86
-
87
- rake db:create
88
-
89
113
  * Setup the test databases
90
114
 
91
- rake db:test:prepare
115
+ rake test:prepare
92
116
 
93
117
  * Run the tests
94
118
 
data/Rakefile CHANGED
@@ -45,49 +45,35 @@ task :clobber => [:clobber_rcov, :clobber_rdoc]
45
45
 
46
46
  begin
47
47
  require 'test/helpers/active_record_test_helper'
48
- namespace :db do
49
- desc "Create the test databases"
50
- task :create do
51
- system "mysqladmin -u root create tenacity_test"
52
- end
53
-
54
- desc "Drop the test databases"
55
- task :drop do
48
+ namespace :test do
49
+ desc "Setup the test databases"
50
+ task :prepare do
56
51
  system "mysqladmin -u root drop -f tenacity_test"
57
- end
58
-
59
- desc "Reset the test databases"
60
- task :reset => [:drop, :create] do
61
- Rake::Task['db:test:prepare'].invoke
62
- end
63
-
64
- namespace :test do
65
- desc "Setup the test databases"
66
- task :prepare do
67
- ActiveRecord::Schema.define :version => 0 do
52
+ system "mysqladmin -u root create tenacity_test"
68
53
 
69
- create_table :active_record_cars, :force => true do |t|
70
- end
54
+ ActiveRecord::Schema.define :version => 0 do
71
55
 
72
- create_table :active_record_climate_control_units, :force => true do |t|
73
- t.string :mongo_mapper_dashboard_id
74
- end
56
+ create_table :active_record_cars, :force => true do |t|
57
+ end
75
58
 
76
- create_table :active_record_cars_mongo_mapper_wheels, :force => true do |t|
77
- t.integer :active_record_car_id
78
- t.string :mongo_mapper_wheel_id
79
- end
59
+ create_table :active_record_climate_control_units, :force => true do |t|
60
+ t.string :mongo_mapper_dashboard_id
61
+ end
80
62
 
81
- create_table :active_record_nuts, :force => true do |t|
82
- t.string :mongo_mapper_wheel_id
83
- end
63
+ create_table :active_record_cars_mongo_mapper_wheels, :force => true do |t|
64
+ t.integer :active_record_car_id
65
+ t.string :mongo_mapper_wheel_id
66
+ end
84
67
 
85
- create_table :active_record_nuts_mongo_mapper_wheels, :force => true do |t|
86
- t.integer :active_record_nut_id
87
- t.string :mongo_mapper_wheel_id
88
- end
68
+ create_table :active_record_nuts, :force => true do |t|
69
+ t.string :mongo_mapper_wheel_id
70
+ end
89
71
 
72
+ create_table :active_record_nuts_mongo_mapper_wheels, :force => true do |t|
73
+ t.integer :active_record_nut_id
74
+ t.string :mongo_mapper_wheel_id
90
75
  end
76
+
91
77
  end
92
78
  end
93
79
  end
data/history.txt ADDED
@@ -0,0 +1,14 @@
1
+ == 0.1.1
2
+
3
+ * Bug fixes
4
+
5
+ * Fixed issue that was causing a load error if mongo mapper was not installed
6
+
7
+ == 0.1.0
8
+
9
+ * Major enhancements
10
+
11
+ * Initial release
12
+ * Support for has_one, belongs_to, and has_many associations
13
+ * Support for ActiveRecord, CouchRest, and MongoMapper
14
+
@@ -217,7 +217,7 @@ module Tenacity
217
217
  end
218
218
  end
219
219
 
220
- def associate_class(association_id)
220
+ def associate_class(association_id) #:nodoc:
221
221
  Kernel.const_get(association_id.to_s.singularize.camelcase.to_sym)
222
222
  end
223
223
 
@@ -1,47 +1,47 @@
1
- # Tenacity relationships on ActiveRecord objects require that certain columns
2
- # exist on the associated table, and that join tables exist for one-to-many
3
- # relationships. Take the following class for example:
4
- #
5
- # class Car < ActiveRecord::Base
6
- # include Tenacity
7
- #
8
- # t_has_many :wheels
9
- # t_has_one :dashboard
10
- # t_belongs_to :driver
11
- # end
12
- #
13
- #
14
- # == t_belongs_to
15
- #
16
- # The +t_belongs_to+ association requires that a property exist in the table
17
- # to hold the id of the assoicated object.
18
- #
19
- # create_table :cars do |t|
20
- # t.string :driver_id
21
- # end
22
- #
23
- #
24
- # == t_has_one
25
- #
26
- # The +t_has_one+ association requires no special column in the table, since
27
- # the associated object holds the foreign key.
28
- #
29
- #
30
- # == t_has_many
31
- #
32
- # The +t_has_many+ association requires that a join table exist to store the
33
- # associations. The name of the join table follows ActiveRecord conventions.
34
- # The name of the join table in this example would be cars_wheels, since cars
35
- # comes before wheels when shorted alphabetically.
36
- #
37
- # create_table :cars_wheels do |t|
38
- # t.integer :car_id
39
- # t.string :wheel_id
40
- # end
41
- #
42
1
  begin
43
2
  require 'active_record'
44
3
 
4
+ # Tenacity relationships on ActiveRecord objects require that certain columns
5
+ # exist on the associated table, and that join tables exist for one-to-many
6
+ # relationships. Take the following class for example:
7
+ #
8
+ # class Car < ActiveRecord::Base
9
+ # include Tenacity
10
+ #
11
+ # t_has_many :wheels
12
+ # t_has_one :dashboard
13
+ # t_belongs_to :driver
14
+ # end
15
+ #
16
+ #
17
+ # == t_belongs_to
18
+ #
19
+ # The +t_belongs_to+ association requires that a property exist in the table
20
+ # to hold the id of the assoicated object.
21
+ #
22
+ # create_table :cars do |t|
23
+ # t.string :driver_id
24
+ # end
25
+ #
26
+ #
27
+ # == t_has_one
28
+ #
29
+ # The +t_has_one+ association requires no special column in the table, since
30
+ # the associated object holds the foreign key.
31
+ #
32
+ #
33
+ # == t_has_many
34
+ #
35
+ # The +t_has_many+ association requires that a join table exist to store the
36
+ # associations. The name of the join table follows ActiveRecord conventions.
37
+ # The name of the join table in this example would be cars_wheels, since cars
38
+ # comes before wheels when shorted alphabetically.
39
+ #
40
+ # create_table :cars_wheels do |t|
41
+ # t.integer :car_id
42
+ # t.string :wheel_id
43
+ # end
44
+ #
45
45
  module ActiveRecord
46
46
  class Base #:nodoc:
47
47
 
@@ -1,41 +1,41 @@
1
- # Tenacity relationships on CouchRest objects require no special keys
2
- # defined on the object. Tenacity will define the keys that it needs
3
- # to support the relationships. Take the following class for example:
4
- #
5
- # class Car < CouchRest::ExtendedDocument
6
- # include Tenacity
7
- #
8
- # t_has_many :wheels
9
- # t_has_one :dashboard
10
- # t_belongs_to :driver
11
- # end
12
- #
13
- # == t_belongs_to
14
- #
15
- # The +t_belongs_to+ association will define a property named after the association.
16
- # The example above will create a property named <tt>:driver_id</tt>
17
- #
18
- #
19
- # == t_has_one
20
- #
21
- # The +t_has_one+ association will not define any new properties on the object, since
22
- # the associated object holds the foreign key. If the CouchRest::ExtendedDocument class
23
- # is the target of a t_has_one association from another class, then a property
24
- # named after the association will be created on the CouchRest::ExtendedDocument object to
25
- # hold the foreign key to the other object.
26
- #
27
- #
28
- # == t_has_many
29
- #
30
- # The +t_has_many+ association will define a property named after the association.
31
- # The example above will create a property named <tt>:wheels_ids</tt>
32
- #
33
-
34
1
  begin
35
2
  require 'couchrest'
36
3
 
37
- module CouchRest
38
- class ExtendedDocument #:nodoc:
4
+ module CouchRest #:nodoc:
5
+
6
+ # Tenacity relationships on CouchRest objects require no special keys
7
+ # defined on the object. Tenacity will define the keys that it needs
8
+ # to support the relationships. Take the following class for example:
9
+ #
10
+ # class Car < CouchRest::ExtendedDocument
11
+ # include Tenacity
12
+ #
13
+ # t_has_many :wheels
14
+ # t_has_one :dashboard
15
+ # t_belongs_to :driver
16
+ # end
17
+ #
18
+ # == t_belongs_to
19
+ #
20
+ # The +t_belongs_to+ association will define a property named after the association.
21
+ # The example above will create a property named <tt>:driver_id</tt>
22
+ #
23
+ #
24
+ # == t_has_one
25
+ #
26
+ # The +t_has_one+ association will not define any new properties on the object, since
27
+ # the associated object holds the foreign key. If the CouchRest::ExtendedDocument class
28
+ # is the target of a t_has_one association from another class, then a property
29
+ # named after the association will be created on the CouchRest::ExtendedDocument object to
30
+ # hold the foreign key to the other object.
31
+ #
32
+ #
33
+ # == t_has_many
34
+ #
35
+ # The +t_has_many+ association will define a property named after the association.
36
+ # The example above will create a property named <tt>:wheels_ids</tt>
37
+ #
38
+ class ExtendedDocument
39
39
  include CouchRest::TenacityInstanceMethods
40
40
  extend CouchRest::TenacityClassMethods
41
41
  end
@@ -1,40 +1,41 @@
1
- # Tenacity relationships on CouchRest objects require no special keys
2
- # defined on the object. Tenacity will define the keys that it needs
3
- # to support the relationships. Take the following class for example:
4
- #
5
- # class Car < CouchRest::Model::Base
6
- # include Tenacity
7
- #
8
- # t_has_many :wheels
9
- # t_has_one :dashboard
10
- # t_belongs_to :driver
11
- # end
12
- #
13
- # == t_belongs_to
14
- #
15
- # The +t_belongs_to+ association will define a property named after the association.
16
- # The example above will create a property named <tt>:driver_id</tt>
17
- #
18
- #
19
- # == t_has_one
20
- #
21
- # The +t_has_one+ association will not define any new properties on the object, since
22
- # the associated object holds the foreign key. If the CouchRest::Model class
23
- # is the target of a t_has_one association from another class, then a property
24
- # named after the association will be created on the CouchRest::Model object to
25
- # hold the foreign key to the other object.
26
- #
27
- #
28
- # == t_has_many
29
- #
30
- # The +t_has_many+ association will define a property named after the association.
31
- # The example above will create a property named <tt>:wheels_ids</tt>
32
- #
33
1
  begin
34
2
  require 'couchrest'
35
3
 
36
- module CouchRest
37
- module Model
4
+ module CouchRest #:nodoc:
5
+ module Model #:nodoc:
6
+
7
+ # Tenacity relationships on CouchRest objects require no special keys
8
+ # defined on the object. Tenacity will define the keys that it needs
9
+ # to support the relationships. Take the following class for example:
10
+ #
11
+ # class Car < CouchRest::Model::Base
12
+ # include Tenacity
13
+ #
14
+ # t_has_many :wheels
15
+ # t_has_one :dashboard
16
+ # t_belongs_to :driver
17
+ # end
18
+ #
19
+ # == t_belongs_to
20
+ #
21
+ # The +t_belongs_to+ association will define a property named after the association.
22
+ # The example above will create a property named <tt>:driver_id</tt>
23
+ #
24
+ #
25
+ # == t_has_one
26
+ #
27
+ # The +t_has_one+ association will not define any new properties on the object, since
28
+ # the associated object holds the foreign key. If the CouchRest::Model class
29
+ # is the target of a t_has_one association from another class, then a property
30
+ # named after the association will be created on the CouchRest::Model object to
31
+ # hold the foreign key to the other object.
32
+ #
33
+ #
34
+ # == t_has_many
35
+ #
36
+ # The +t_has_many+ association will define a property named after the association.
37
+ # The example above will create a property named <tt>:wheels_ids</tt>
38
+ #
38
39
  class Base
39
40
  include CouchRest::TenacityInstanceMethods
40
41
  extend CouchRest::TenacityClassMethods
@@ -1,5 +1,5 @@
1
1
  module CouchRest
2
- module TenacityClassMethods
2
+ module TenacityClassMethods #:nodoc:
3
3
  def _t_find(id)
4
4
  get(id)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module CouchRest
2
- module TenacityInstanceMethods
2
+ module TenacityInstanceMethods #:nodoc:
3
3
  def _t_reload
4
4
  new_doc = database.get(self.id)
5
5
  self.clear
@@ -101,7 +101,7 @@ end
101
101
  begin
102
102
  require 'mongo_mapper'
103
103
  MongoMapper::Document.append_inclusions(TenacityPluginAddition)
104
- rescue
104
+ rescue LoadError
105
105
  # MongoMapper not available
106
106
  end
107
107
 
@@ -1,3 +1,3 @@
1
1
  module Tenacity
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/tenacity.gemspec CHANGED
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.summary = %Q{A ORM independent way of specifying simple relationships between models backed by different databases.}
13
13
  s.description = %Q{Tenacity provides an ORM independent way of specifying simple relationships between models backed by different databases.}
14
14
 
15
+ s.rubyforge_project = "tenacity"
16
+
15
17
  s.required_rubygems_version = ">= 1.3.6"
16
18
 
17
19
  s.add_runtime_dependency "activesupport", ">= 2.3"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Wood
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-25 00:00:00 -06:00
17
+ date: 2010-12-29 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -185,6 +185,7 @@ files:
185
185
  - LICENSE.txt
186
186
  - README.rdoc
187
187
  - Rakefile
188
+ - history.txt
188
189
  - lib/tenacity.rb
189
190
  - lib/tenacity/associations/belongs_to.rb
190
191
  - lib/tenacity/associations/has_many.rb
@@ -244,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
245
  version: 1.3.6
245
246
  requirements: []
246
247
 
247
- rubyforge_project:
248
+ rubyforge_project: tenacity
248
249
  rubygems_version: 1.3.6
249
250
  signing_key:
250
251
  specification_version: 3