acts_as_relatable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -10,7 +10,7 @@ Gem installation :
|
|
10
10
|
|
11
11
|
Or you can put it in your Gemfile :
|
12
12
|
|
13
|
-
gem "acts_as_relatable"
|
13
|
+
gem "acts_as_relatable", "~> 0.0.3"
|
14
14
|
|
15
15
|
and then run :
|
16
16
|
|
@@ -28,7 +28,7 @@ Followed by :
|
|
28
28
|
|
29
29
|
# Model definition
|
30
30
|
|
31
|
-
class
|
31
|
+
class Tool < ActiveRecord::Base
|
32
32
|
acts_as_relatable :product
|
33
33
|
end
|
34
34
|
|
@@ -36,21 +36,27 @@ Followed by :
|
|
36
36
|
acts_as_relatable :recipe
|
37
37
|
end
|
38
38
|
|
39
|
+
class Recipe < ActiveRecord::Base
|
40
|
+
acts_as_relatable :product, :tool
|
41
|
+
end
|
42
|
+
|
39
43
|
# Create some entries
|
40
44
|
|
41
45
|
@bread = Product.create(:name => "Bread")
|
42
46
|
@butter = Product.create(:name => "Butter")
|
43
47
|
@pancake = Recipe.create(:name => "Pancakes")
|
48
|
+
@mixer = Tool.create(:name => "Mixer")
|
44
49
|
|
45
50
|
|
46
51
|
#Creating relationships
|
47
52
|
|
48
|
-
@butter.relates_to!(@pancake) # #<ActsAsRelatable::Relationship id: 2, relator_id:
|
49
|
-
@
|
53
|
+
@butter.relates_to!(@pancake) # #<ActsAsRelatable::Relationship id: 2, relator_id: 2, relator_type: "Product", related_id: 1, related_type: "Recipe">
|
54
|
+
@pancake.relates_to!(@mixer) # #<ActsAsRelatable::Relationship id: 3, relator_id: 1, relator_type: "Recipe", related_id: 1, related_type: "Tool">
|
55
|
+
@bread.relates_to!(@butter) # #<ActsAsRelatable::Relationship id: 4, relator_id: 1, relator_type: "Product", related_id: 2, related_type: "Product">
|
50
56
|
|
51
57
|
# By default, relationships are both-sided, it means that on the first line above,
|
52
58
|
# @butter is related to @pancake, but @pancake is also related to @butter.
|
53
|
-
#If you don't want/need this behaviour, you can pass false as a second argument
|
59
|
+
# If you don't want/need this behaviour, you can pass false as a second argument
|
54
60
|
# to the relates_to! instance method :
|
55
61
|
|
56
62
|
@butter.relates_to!(@pancake, false)
|
@@ -63,6 +69,7 @@ Followed by :
|
|
63
69
|
|
64
70
|
|
65
71
|
@butter.relateds # {:recipes=>[#<Recipe id: 1, name: "Pancakes">], :products=>[#<Product id: 1, name: "Bread">]}
|
72
|
+
@pancake.relateds # {:tools=>[#<Tool id: 1, name: "Mixer">], :products=>[#<Product id: 2, name: "Butter">]}
|
66
73
|
|
67
74
|
#Testing relationships
|
68
75
|
|
@@ -74,6 +81,30 @@ Followed by :
|
|
74
81
|
|
75
82
|
@butter.destroy_relation_with @pancake
|
76
83
|
|
84
|
+
== Configuration
|
85
|
+
|
86
|
+
To create the acts_as_relatable config file, open a shell and run :
|
87
|
+
|
88
|
+
r g acts_as_relatable:config
|
89
|
+
|
90
|
+
It will create a file called acts_as_relatable.rb in config/initializers
|
91
|
+
|
92
|
+
== Relationship Shortcut
|
93
|
+
|
94
|
+
By default, the Relationship model is accessible with :
|
95
|
+
|
96
|
+
ActsAsRelatable::Relationship
|
97
|
+
ActsAsRelatable::Relationship.count
|
98
|
+
|
99
|
+
If you want to access it directly with
|
100
|
+
|
101
|
+
Relationship
|
102
|
+
Relationship.first
|
103
|
+
|
104
|
+
Just uncomment this line in the config file (see Configuration section above to see how to generate it)
|
105
|
+
|
106
|
+
Relationship = ActsAsRelatable::Relationship
|
107
|
+
|
77
108
|
== Relationship model extension
|
78
109
|
|
79
110
|
You can add class/instance methods to the ActsAsRelatable::Relationship model
|
@@ -103,11 +134,8 @@ Let's call this module RelationshipExtension. The file may look like :
|
|
103
134
|
end
|
104
135
|
end
|
105
136
|
|
106
|
-
In a shell, run :
|
107
137
|
|
108
|
-
|
109
|
-
|
110
|
-
It will create a file called acts_as_relatable.rb in config/initializers
|
138
|
+
Generate the config file (see Configuration section above to see how to generate it)
|
111
139
|
|
112
140
|
Open this file and uncomment this line :
|
113
141
|
|
@@ -1,2 +1,5 @@
|
|
1
1
|
# Uncomment the following line if you want to add methods to the ActsAsRelatable::Relationship AR model
|
2
|
-
#ActsAsRelatable::Relationship.send(:include, RelationshipExtension)
|
2
|
+
#ActsAsRelatable::Relationship.send(:include, RelationshipExtension)
|
3
|
+
|
4
|
+
#Uncomment this line if you want a shortcut for the Relationship class
|
5
|
+
#Relationship = ActsAsRelatable::Relationship
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: acts_as_relatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Fr\xC3\xA9d\xC3\xA9ric Malamitsas"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-17 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|