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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 215
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
163
164
165
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 163
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 200
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
192
193
194
195
196
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 192
def direct_followers
direct_follower_ids.map do |id|
Card.fetch(id)
end
end
|
#follow_label ⇒ Object
82
83
84
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 82
def follow_label
name
end
|
#follow_option? ⇒ Boolean
101
102
103
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 101
def follow_option?
codename && FollowOption.codenames.include?(codename.to_sym)
end
|
#follow_rule_applies?(follower_id) ⇒ Boolean
126
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
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 126
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
97
98
99
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 97
def follow_rule_card?
is_user_rule? && rule_setting_name == '*follow'
end
|
#followed? ⇒ Boolean
121
122
123
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 121
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
109
110
111
112
113
114
115
116
117
118
119
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 109
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
170
171
172
173
174
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 170
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 176
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
92
93
94
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 92
def follower_names
followers.map(&:name)
end
|
#followers ⇒ Object
86
87
88
89
90
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 86
def followers
follower_ids.map do |id|
Card.fetch(id)
end
end
|
#read_follower_ids_cache ⇒ Object
240
241
242
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 240
def read_follower_ids_cache
Card.follower_ids_cache[id]
end
|
#with_follower_candidate_ids ⇒ Object
155
156
157
158
159
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 155
def with_follower_candidate_ids
@follower_candidate_ids = {}
yield
@follower_candidate_ids = nil
end
|
#write_follower_ids_cache(user_ids) ⇒ Object
234
235
236
237
238
|
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 234
def write_follower_ids_cache user_ids
hash = Card.follower_ids_cache
hash[id] = user_ids
Card.write_follower_ids_cache hash
end
|