party_boy 0.2.0 → 0.2.3
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.
- data/VERSION +1 -1
- data/lib/party_boy.rb +13 -16
- data/party_boy.gemspec +2 -2
- data/spec/party_boy_spec.rb +26 -1
- data/spec/schema.rb +1 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/party_boy.rb
CHANGED
@@ -48,11 +48,7 @@ module Party
|
|
48
48
|
end
|
49
49
|
|
50
50
|
obj = (obj.class == Class && obj || obj.class == String && obj.classify.constantize || obj.class)
|
51
|
-
|
52
|
-
super_class_name(obj.superclass)
|
53
|
-
else
|
54
|
-
obj.name
|
55
|
-
end
|
51
|
+
obj.base_class.name
|
56
52
|
end
|
57
53
|
|
58
54
|
def get_relationship_to(requestee)
|
@@ -103,10 +99,10 @@ module Party
|
|
103
99
|
follows.unblocked.to_type(type).size
|
104
100
|
end
|
105
101
|
|
106
|
-
def followers(type = nil)
|
102
|
+
def followers(type = nil, includes = {})
|
107
103
|
super_class = super_class_name(type)
|
108
104
|
exact_class = type && type.to_s.classify
|
109
|
-
results = relationships_from(super_class)
|
105
|
+
results = relationships_from(super_class, includes)
|
110
106
|
if super_class && exact_class && super_class != exact_class
|
111
107
|
results.collect{|relationship| requestor = relationship.requestor; requestor.class.name == exact_class && requestor || nil}.compact
|
112
108
|
else
|
@@ -115,10 +111,10 @@ module Party
|
|
115
111
|
|
116
112
|
end
|
117
113
|
|
118
|
-
def following(type = nil)
|
114
|
+
def following(type = nil, includes = {})
|
119
115
|
super_class = super_class_name(type)
|
120
116
|
exact_class = type && type.to_s.classify
|
121
|
-
results = relationships_to(super_class)
|
117
|
+
results = relationships_to(super_class, includes)
|
122
118
|
if super_class && exact_class && super_class != exact_class
|
123
119
|
results.collect{|relationship| requestee = relationship.requestee; requestee.class.name == exact_class && requestee || nil}.compact
|
124
120
|
else
|
@@ -135,13 +131,14 @@ module Party
|
|
135
131
|
end
|
136
132
|
|
137
133
|
def method_missing(method, *args)
|
134
|
+
includes = args[0] || {}
|
138
135
|
case method.id2name
|
139
136
|
when /^(.+)ss_followers$/
|
140
|
-
followers("#{$1}ss".classify)
|
137
|
+
followers("#{$1}ss".classify, includes)
|
141
138
|
when /^(.+)s_followers$/, /^(.+)_followers$/
|
142
|
-
followers($1.classify)
|
139
|
+
followers($1.classify, includes)
|
143
140
|
when /^following_(.+)$/
|
144
|
-
following($1.classify)
|
141
|
+
following($1.classify, includes)
|
145
142
|
else
|
146
143
|
super
|
147
144
|
end
|
@@ -166,12 +163,12 @@ module Party
|
|
166
163
|
|
167
164
|
private
|
168
165
|
|
169
|
-
def relationships_to(type)
|
170
|
-
self.follows.unblocked.to_type(type).all(:include => [:requestee])
|
166
|
+
def relationships_to(type, includes = {})
|
167
|
+
self.follows.unblocked.to_type(type).all(:include => [:requestee => includes])
|
171
168
|
end
|
172
169
|
|
173
|
-
def relationships_from(type)
|
174
|
-
self.followings.unblocked.from_type(type).all(:include => [:requestor])
|
170
|
+
def relationships_from(type, includes = {})
|
171
|
+
self.followings.unblocked.from_type(type).all(:include => [:requestor => includes])
|
175
172
|
end
|
176
173
|
|
177
174
|
end
|
data/party_boy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{party_boy}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mike Nelson"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-04}
|
13
13
|
s.description = %q{Models relationships between AR models. Allows you to follow, friend, and block other AR's. Consists of two mixins: acts_as_followable and acts_as_friend. These options allow an AR to inherit either a twitter-like follower system or a facebook-like friend system.}
|
14
14
|
s.email = %q{mdnelson30@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/party_boy_spec.rb
CHANGED
@@ -127,7 +127,9 @@ describe "party_boy -- follower" do
|
|
127
127
|
|
128
128
|
|
129
129
|
class User < FollowerClass; end
|
130
|
-
class Business < FollowerClass;
|
130
|
+
class Business < FollowerClass;
|
131
|
+
has_many :programs
|
132
|
+
end
|
131
133
|
class Program < FollowerClass; end
|
132
134
|
|
133
135
|
it "should handle STI properly" do
|
@@ -186,6 +188,29 @@ describe "party_boy -- follower" do
|
|
186
188
|
|
187
189
|
end
|
188
190
|
|
191
|
+
it "should handle includes properly" do
|
192
|
+
u = User.create
|
193
|
+
b = Business.create
|
194
|
+
b2 = Business.create
|
195
|
+
b3 = Business.create
|
196
|
+
|
197
|
+
[b,b2,b3].each{|biz| biz.programs.create}
|
198
|
+
|
199
|
+
u.follow(b)
|
200
|
+
u.follow(b2)
|
201
|
+
u.follow(b3)
|
202
|
+
|
203
|
+
bizs = u.following_businesses(:programs)
|
204
|
+
bizs.each do |biz|
|
205
|
+
biz.programs.loaded?.should be_true
|
206
|
+
end
|
207
|
+
|
208
|
+
bizs = u.following_businesses
|
209
|
+
bizs.each do |biz|
|
210
|
+
biz.programs.loaded?.should be_false
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
189
214
|
end
|
190
215
|
|
191
216
|
|
data/spec/schema.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Nelson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-04 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|