bigamy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +62 -3
- data/VERSION +1 -1
- data/bigamy.gemspec +1 -1
- data/lib/bigamy.rb +7 -6
- data/test/unit/test_ar_side.rb +6 -6
- metadata +2 -2
data/README
CHANGED
@@ -1,11 +1,70 @@
|
|
1
1
|
= Bigamy
|
2
|
-
|
3
2
|
Enable seamless Ruby-ness between ActiveRecord objects & MongoMapper documents
|
4
3
|
|
5
|
-
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
Bigamy.setup self
|
6
|
+
|
7
|
+
has_one_mm :doc
|
8
|
+
has_many_mm :photos
|
9
|
+
end
|
10
|
+
|
11
|
+
class Doc
|
12
|
+
include MongoMapper::Document
|
13
|
+
Bigamy.setup self
|
14
|
+
|
15
|
+
belongs_to_ar :user
|
16
|
+
end
|
17
|
+
|
18
|
+
class Photo
|
19
|
+
include MongoMapper::Document
|
20
|
+
Bigamy.setup self
|
21
|
+
|
22
|
+
belongs_to_ar :user
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
Bigamy sets foreign keys upon assignment. It doesn't keep track of dirty children.
|
27
|
+
It doesn't allow you to operate with new records. So when you do:
|
28
|
+
|
29
|
+
@user.doc = @doc
|
30
|
+
|
31
|
+
- @user has to be saved already.
|
32
|
+
- @doc has to be saved already.
|
33
|
+
- @doc will have it's user_id attribute updated immediately.
|
34
|
+
|
35
|
+
When you do:
|
36
|
+
|
37
|
+
@user.photos = Photo.all
|
6
38
|
|
39
|
+
- every Photo document will have it's user_id attribute set immediately
|
40
|
+
|
41
|
+
|
42
|
+
== Options
|
43
|
+
The available class methods are:
|
44
|
+
|
45
|
+
For AR:
|
46
|
+
belongs_to_mm
|
47
|
+
has_one_mm
|
48
|
+
has_many_mm
|
49
|
+
|
50
|
+
For MM:
|
51
|
+
belongs_to_ar
|
52
|
+
has_one_ar
|
53
|
+
has_many_ar
|
54
|
+
|
55
|
+
All class methods take :foreign_key, :class, and :primary_key options as a hash
|
56
|
+
|
57
|
+
|
58
|
+
== Setup
|
59
|
+
Bigamy.setup can take any number of classes as arguments, and can be in an initializer like:
|
60
|
+
|
61
|
+
Bigamy.setup User, Doc
|
62
|
+
|
63
|
+
|
64
|
+
= License
|
7
65
|
Bigmay is released under the MIT license.
|
8
66
|
|
9
|
-
|
67
|
+
It's developed by Ryan Angilly and released with the permission of MyPunchbowl.com
|
10
68
|
|
69
|
+
= Support
|
11
70
|
Just email me at ryan@angilly.com with questions, bugs, or patches.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bigamy.gemspec
CHANGED
data/lib/bigamy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mongo_mapper'
|
2
|
+
require 'active_record'
|
2
3
|
require 'set'
|
3
4
|
|
4
5
|
require 'bigamy/proxy'
|
@@ -39,15 +40,15 @@ module Bigamy
|
|
39
40
|
self.bigamy_associations.each {|k,v| v.divorce_everyone }
|
40
41
|
end
|
41
42
|
|
42
|
-
def belongs_to_ar name, options = {}
|
43
|
+
def belongs_to_ar name, options = {}
|
43
44
|
bigamy_associations[name] = MongoBelongsTo.new(self, name, options)
|
44
45
|
end
|
45
46
|
|
46
|
-
def has_one_ar name, options = {}
|
47
|
+
def has_one_ar name, options = {}
|
47
48
|
bigamy_associations[name] = MongoHasOne.new(self, name, options)
|
48
49
|
end
|
49
50
|
|
50
|
-
def has_many_ar name, options = {}
|
51
|
+
def has_many_ar name, options = {}
|
51
52
|
bigamy_associations[name] = MongoHasMany.new(self, name, options)
|
52
53
|
end
|
53
54
|
end
|
@@ -84,15 +85,15 @@ module Bigamy
|
|
84
85
|
self.bigamy_associations.each {|k,v| v.divorce_everyone }
|
85
86
|
end
|
86
87
|
|
87
|
-
def
|
88
|
+
def belongs_to_mm name, options = {}
|
88
89
|
bigamy_associations[name] = ARBelongsTo.new(self, name, options)
|
89
90
|
end
|
90
91
|
|
91
|
-
def
|
92
|
+
def has_one_mm name, options = {}
|
92
93
|
bigamy_associations[name] = ARHasOne.new(self, name, options)
|
93
94
|
end
|
94
95
|
|
95
|
-
def
|
96
|
+
def has_many_mm name, options = {}
|
96
97
|
bigamy_associations[name] = ARHasMany.new(self, name, options)
|
97
98
|
end
|
98
99
|
end
|
data/test/unit/test_ar_side.rb
CHANGED
@@ -34,9 +34,9 @@ class TestArSide < Test::Unit::TestCase
|
|
34
34
|
assert User.respond_to?(:divorce_everyone)
|
35
35
|
end
|
36
36
|
|
37
|
-
context "that
|
37
|
+
context "that has_one_mm :doc" do
|
38
38
|
setup do
|
39
|
-
User.
|
39
|
+
User.has_one_mm :doc
|
40
40
|
@doc = Doc.create!
|
41
41
|
end
|
42
42
|
|
@@ -71,9 +71,9 @@ class TestArSide < Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
context "that
|
74
|
+
context "that has_many_mm :doc" do
|
75
75
|
setup do
|
76
|
-
User.
|
76
|
+
User.has_many_mm :docs
|
77
77
|
end
|
78
78
|
|
79
79
|
should "create accessors" do
|
@@ -117,9 +117,9 @@ class TestArSide < Test::Unit::TestCase
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
context "that
|
120
|
+
context "that belongs_to_mm :doc" do
|
121
121
|
setup do
|
122
|
-
User.
|
122
|
+
User.belongs_to_mm :doc
|
123
123
|
end
|
124
124
|
|
125
125
|
should "create accessors" do
|