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, 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_reasonObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 207

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



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

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



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 192

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_followersObject



184
185
186
187
188
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 184

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

#follow_labelObject



74
75
76
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 74

def follow_label
  name
end

#follow_option?Boolean

Returns:

  • (Boolean)


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

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

#follow_rule_applies?(follower_id) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 118

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

Returns:

  • (Boolean)


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

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

#followed?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 113

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)


101
102
103
104
105
106
107
108
109
110
111
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 101

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

Returns:

  • (Boolean)


162
163
164
165
166
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 162

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



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 168

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



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

def follower_names
  followers.map(&:name)
end

#followersObject



78
79
80
81
82
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 78

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

#read_follower_ids_cacheObject



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

def read_follower_ids_cache
  Card.follower_ids_cache[id]
end

#with_follower_candidate_idsObject



147
148
149
150
151
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 147

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

#write_follower_ids_cache(user_ids) ⇒ Object

~~~~~ cache methods



226
227
228
229
230
# File 'tmpsets/set/mod006-05_email/all/follow.rb', line 226

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