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?, clean_empty_module_from_hash, clean_empty_modules, define_on_format, each_format, ensure_set, extended, format, include_set, include_set_formats, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file

Methods included from Trait

#card_accessor, #card_reader, #card_writer

Methods included from Event

#define_event, #event

Instance Method Details

#all_direct_follower_ids_with_reasonObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 211

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_cardObject

the set card to be followed if you want to follow changes of card



159
160
161
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 159

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



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 196

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) && self.follow_rule_applies?(user_id)
          result << user_id
        end
      end
    end
  end
  result
end

#direct_followersObject



187
188
189
190
191
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 187

def direct_followers
  direct_follower_ids.map do |id|
    Card.fetch(id)
  end
end

#follow_labelObject



86
87
88
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 86

def follow_label
  name
end

#follow_option?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 104

def follow_option?
  codename && FollowOption.codenames.include?(codename.to_sym)
end

#follow_rule_applies?(follower_id) ⇒ Boolean

Returns:

  • (Boolean)


125
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
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 125

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
  false
end

#follow_rule_card?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 100

def follow_rule_card?
  is_user_rule? && rule_setting_name == '*follow'
end

#followed?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


111
112
113
114
115
116
117
118
119
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 111

def followed_by? user_id
  with_follower_candidate_ids do
    return true if follow_rule_applies? user_id
    return true if (left_card = left) &&
                   left_card.followed_field?(self) &&
                   left_card.followed_by?(user_id)
    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

Returns:

  • (Boolean)


165
166
167
168
169
170
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 165

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_idsObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 172

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_namesObject



96
97
98
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 96

def follower_names
  followers.map(&:name)
end

#followersObject



90
91
92
93
94
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 90

def followers
  follower_ids.map do |id|
    Card.fetch(id)
  end
end

#read_follower_ids_cacheObject



235
236
237
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 235

def read_follower_ids_cache
  Card.follower_ids_cache[id]
end

#with_follower_candidate_idsObject



152
153
154
155
156
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 152

def with_follower_candidate_ids
  @follower_candidate_ids = {}
  yield
  @follower_candidate_ids = nil
end

#write_follower_ids_cache(user_ids) ⇒ Object

~~~~~ cache methods



229
230
231
232
233
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 229

def write_follower_ids_cache user_ids
  hash = Card.follower_ids_cache
  hash[id] = user_ids
  Card.write_follower_ids_cache hash
end