Module: Party::Boy::FollowableInstanceMethods
- Defined in:
- lib/party_boy.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/party_boy.rb', line 133
def method_missing(method, *args)
begin
super
rescue NoMethodError, NameError => e
includes = args[0] || {}
case method.to_s
when /^(.+)ss_followers$/
followers("#{$1}ss".classify, includes)
when /^(.+)s_followers$/, /^(.+)_followers$/
followers($1.classify, includes)
when /^following_(.+)$/
following($1.classify, includes)
else
raise e
end
end
end
|
Instance Method Details
#block(something) ⇒ Object
90
91
92
|
# File 'lib/party_boy.rb', line 90
def block(something)
(rel = (get_relationship_from(something) || get_relationship_to(something))) && rel.update_attribute(:restricted, true)
end
|
#blocked_by?(something) ⇒ Boolean
82
83
84
|
# File 'lib/party_boy.rb', line 82
def blocked_by?(something)
!!(something && Relationship.blocked.count(:conditions => ['requestor_id = ? and requestor_type = ? and requestee_id = ? and requestee_type = ?', self.id, super_class_name, something.id, super_class_name(something)]) > 0)
end
|
#extended_network(type = nil) ⇒ Object
129
130
131
|
# File 'lib/party_boy.rb', line 129
def extended_network(type = nil)
network(type).collect{|friend| friend.methods.include?('network') && friend.network(type) || []}.flatten.uniq
end
|
#follow(something) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/party_boy.rb', line 74
def follow(something)
if blocked_by?(something)
raise(Party::Boy::StalkerError, "#{super_class_name} #{self.id} has been blocked by #{super_class_name(something)} #{something.id} but is trying to follow them")
elsif !following?(something)
Relationship.create(:requestor => self, :requestee => something, :restricted => false)
end
end
|
#followed_by?(something) ⇒ Boolean
70
71
72
|
# File 'lib/party_boy.rb', line 70
def followed_by?(something)
!!(something && Relationship.unblocked.count(:conditions => ['requestor_id = ? and requestor_type = ? and requestee_id = ? and requestee_type = ?', something.id, super_class_name(something), self.id, super_class_name]) > 0)
end
|
#follower_count(type = nil) ⇒ Object
94
95
96
|
# File 'lib/party_boy.rb', line 94
def follower_count(type = nil)
followings.unblocked.from_type(type).size
end
|
#followers(type = nil, includes = {}) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/party_boy.rb', line 102
def followers(type = nil, includes = {})
super_class = super_class_name(type)
exact_class = type && type.to_s.classify
results = relationships_from(super_class, includes)
if super_class && exact_class && super_class != exact_class
results.collect{|relationship| requestor = relationship.requestor; requestor.class.name == exact_class && requestor || nil}.compact
else
results.collect{|relationship| relationship.requestor}
end
end
|
#following(type = nil, includes = {}) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/party_boy.rb', line 114
def following(type = nil, includes = {})
super_class = super_class_name(type)
exact_class = type && type.to_s.classify
results = relationships_to(super_class, includes)
if super_class && exact_class && super_class != exact_class
results.collect{|relationship| requestee = relationship.requestee; requestee.class.name == exact_class && requestee || nil}.compact
else
results.collect{|relationship| relationship.requestee}
end
end
|
#following?(something) ⇒ Boolean
66
67
68
|
# File 'lib/party_boy.rb', line 66
def following?(something)
!!(something && Relationship.unblocked.count(:conditions => ['requestor_id = ? and requestor_type = ? and requestee_id = ? and requestee_type = ?', self.id, super_class_name, something.id, super_class_name(something)]) > 0)
end
|
#following_count(type = nil) ⇒ Object
98
99
100
|
# File 'lib/party_boy.rb', line 98
def following_count(type = nil)
follows.unblocked.to_type(type).size
end
|
#network(type = nil) ⇒ Object
125
126
127
|
# File 'lib/party_boy.rb', line 125
def network(type = nil)
[following(type), followers(type)].flatten.uniq
end
|
#respond_to?(name, include_private = false) ⇒ Boolean
151
152
153
154
155
|
# File 'lib/party_boy.rb', line 151
def respond_to?(name, include_private = false)
return true if super
[/^(.+)ss_followers$/, /^(.+)s_followers$/, /^(.+)_followers$/, /^following_(.+)$/].each{|reg| return true if name.to_s =~ reg}
false
end
|
#unfollow(something) ⇒ Object
86
87
88
|
# File 'lib/party_boy.rb', line 86
def unfollow(something)
(rel = get_relationship_to(something)) && rel.destroy
end
|