Module: Card::Set::All::Follow

Extended by:
Card::Set
Defined in:
tmpsets/set/mod012-email/all/follow.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

FOLLOWER_IDS_CACHE_KEY =
"FOLLOWER_IDS".freeze

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #pattern_and_modules_from_path, #process_base_modules, #register_set, #tmp_file_frame, #tmp_file_template, #tmp_file_wrapped_content, #write_tmp_file

Methods included from Helpers

#abstract_set?, #all_set?, #shortname

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer

Methods included from Event

#event

Instance Method Details

#all_direct_follower_ids_with_reasonObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'tmpsets/set/mod012-email/all/follow.rb', line 205

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|
        next if visited.include?(user_id) ||
                !(follow_option = follow_rule_applies?(user_id))
        visited << user_id
        yield(user_id, set_card: set_card, option: follow_option)
      end
    end
  end
end

#default_follow_set_cardObject

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



153
154
155
# File 'tmpsets/set/mod012-email/all/follow.rb', line 153

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



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'tmpsets/set/mod012-email/all/follow.rb', line 190

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

#direct_followersObject



181
182
183
184
185
# File 'tmpsets/set/mod012-email/all/follow.rb', line 181

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

#follow_labelObject



80
81
82
# File 'tmpsets/set/mod012-email/all/follow.rb', line 80

def follow_label
  name
end

#follow_option?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'tmpsets/set/mod012-email/all/follow.rb', line 98

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

#follow_rule_applies?(follower_id) ⇒ Boolean

Returns:

  • (Boolean)


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/mod012-email/all/follow.rb', line 119

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)


94
95
96
# File 'tmpsets/set/mod012-email/all/follow.rb', line 94

def follow_rule_card?
  is_preference? && rule_setting_name == "*follow"
end

#followed?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'tmpsets/set/mod012-email/all/follow.rb', line 115

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)


105
106
107
108
109
110
111
112
113
# File 'tmpsets/set/mod012-email/all/follow.rb', line 105

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)


159
160
161
162
163
164
165
166
# File 'tmpsets/set/mod012-email/all/follow.rb', line 159

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
# File 'tmpsets/set/mod012-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
      result += left_card.direct_follower_ids if left_card.followed_field? self
      left_card = left_card.left
    end
    write_follower_ids_cache result
    result
  end
end

#follower_namesObject



90
91
92
# File 'tmpsets/set/mod012-email/all/follow.rb', line 90

def follower_names
  followers.map(&:name)
end

#followersObject



84
85
86
87
88
# File 'tmpsets/set/mod012-email/all/follow.rb', line 84

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

#read_follower_ids_cacheObject



228
229
230
# File 'tmpsets/set/mod012-email/all/follow.rb', line 228

def read_follower_ids_cache
  Card.follower_ids_cache[id]
end

#with_follower_candidate_idsObject



146
147
148
149
150
# File 'tmpsets/set/mod012-email/all/follow.rb', line 146

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

#write_follower_ids_cache(user_ids) ⇒ Object

~~~~~ cache methods



222
223
224
225
226
# File 'tmpsets/set/mod012-email/all/follow.rb', line 222

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