Module: Card::Set::All::Follow
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod006-05_email/all/follow.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- FOLLOWER_IDS_CACHE_KEY =
'FOLLOWER_IDS'
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file
Instance Method Details
#all_direct_follower_ids_with_reason ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 216
def all_direct_follower_ids_with_reason
with_follower_candidate_ids do
visited = ::Set.new
set_names.each do |set_name|
set_card = Card.fetch(set_name)
set_card.all_user_ids_with_rule_for(:follow).each do |user_id|
if (!visited.include?(user_id)) && (follow_option = self.follow_rule_applies?(user_id))
visited << user_id
yield(user_id, set_card: set_card, option: follow_option)
end
end
end
end
end
|
#default_follow_set_card ⇒ Object
the set card to be followed if you want to follow changes of card
164
165
166
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 164
def default_follow_set_card
Card.fetch("#{name}+*self")
end
|
#direct_follower_ids(args = {}) ⇒ Object
all ids of users that follow this card because of a follow rule that applies to this card doesn’t include users that follow this card because they are following parent cards or other cards that include this card
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 201
def direct_follower_ids args={}
result = ::Set.new
with_follower_candidate_ids do
set_names.each do |set_name|
set_card = Card.fetch(set_name)
set_card.all_user_ids_with_rule_for(:follow).each do |user_id|
if (!result.include? user_id) and self.follow_rule_applies?(user_id)
result << user_id
end
end
end
end
result
end
|
#direct_followers ⇒ Object
193
194
195
196
197
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 193
def direct_followers
direct_follower_ids.map do |id|
Card.fetch(id)
end
end
|
#follow_label ⇒ Object
83
84
85
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 83
def follow_label
name
end
|
#follow_option? ⇒ Boolean
102
103
104
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 102
def follow_option?
codename && FollowOption.codenames.include?(codename.to_sym)
end
|
#follow_rule_applies?(follower_id) ⇒ Boolean
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 127
def follow_rule_applies? follower_id
follow_rule = rule :follow, user_id: follower_id
if follow_rule.present?
follow_rule.split("\n").each do |value|
value_code = value.to_name.code
accounted_ids = (
@follower_candidate_ids[ value_code ] ||=
if block = FollowOption.follower_candidate_ids[ value_code ]
block.call self
else
[]
end
)
applicable =
if test = FollowOption.test[ value_code ]
test.call follower_id, accounted_ids
else
accounted_ids.include? follower_id
end
return value.gsub( /[\[\]]/, '' ) if applicable
end
end
return false
end
|
#follow_rule_card? ⇒ Boolean
98
99
100
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 98
def follow_rule_card?
is_user_rule? && rule_setting_name == '*follow'
end
|
#followed? ⇒ Boolean
122
123
124
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 122
def followed?
followed_by? Auth.current_id
end
|
#followed_by?(user_id) ⇒ Boolean
used for the follow menu overwritten in type/set.rb and type/cardtype.rb for sets and cardtypes it doesn’t check whether the users is following the card itself instead it checks whether he is following the complete set
110
111
112
113
114
115
116
117
118
119
120
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 110
def followed_by? user_id
with_follower_candidate_ids do
if follow_rule_applies? user_id
return true
end
if left_card = left and left_card.followed_field?(self) && left_card.followed_by?(user_id)
return true
end
return false
end
end
|
#followed_field?(field_card) ⇒ Boolean
returns true if according to the follow_field_rule followers of self also follow changes of field_card
171
172
173
174
175
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 171
def followed_field? field_card
(follow_field_rule = rule_card(:follow_fields)) || follow_field_rule.item_names.find do |item|
item.to_name.key == field_card.key || (item.to_name.key == Card[:includes].key && included_card_ids.include?(field_card.id) )
end
end
|
#follower_ids ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 177
def follower_ids
@follower_ids = read_follower_ids_cache || begin
result = direct_follower_ids
left_card = left
while left_card
if left_card.followed_field? self
result += left_card.direct_follower_ids
end
left_card = left_card.left
end
write_follower_ids_cache result
result
end
end
|
#follower_names ⇒ Object
93
94
95
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 93
def follower_names
followers.map(&:name)
end
|
#followers ⇒ Object
87
88
89
90
91
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 87
def followers
follower_ids.map do |id|
Card.fetch(id)
end
end
|
#read_follower_ids_cache ⇒ Object
241
242
243
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 241
def read_follower_ids_cache
Card.follower_ids_cache[id]
end
|
#with_follower_candidate_ids ⇒ Object
156
157
158
159
160
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 156
def with_follower_candidate_ids
@follower_candidate_ids = {}
yield
@follower_candidate_ids = nil
end
|
#write_follower_ids_cache(user_ids) ⇒ Object
235
236
237
238
239
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 235
def write_follower_ids_cache user_ids
hash = Card.follower_ids_cache
hash[id] = user_ids
Card.write_follower_ids_cache hash
end
|