Class: Card::Set::All::Notify::FollowerStash

Inherits:
Object
  • Object
show all
Defined in:
tmpsets/set/mod006-05_email/all/notify.rb

Overview

~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/05_email/set/all/notify.rb ~~~~~~~~~~~

Instance Method Summary collapse

Constructor Details

#initialize(card = nil) ⇒ FollowerStash

Returns a new instance of FollowerStash.



6
7
8
9
10
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 6

def initialize card=nil
  @followed_affected_cards = Hash.new { |h, v| h[v] = [] }
  @visited = ::Set.new
  add_affected_card(card) if card
end

Instance Method Details

#add_affected_card(card) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 12

def add_affected_card card
  return if @visited.include? card.key
  Auth.as_bot do
    @visited.add card.key
    notify_direct_followers card
    return if !(left_card = card.left) || @visited.include?(left_card.key) ||
              !(follow_field_rule = left_card.rule_card(:follow_fields))
    follow_field_rule.item_names(context: left_card.cardname).each do |item|
      if @visited.include? item.to_name.key
        add_affected_card left_card
        break
      elsif item.to_name.key == Card[:includes].key
        includee_set = Card.search(
          { included_by: left_card.name },
          "follow cards included by #{left_card.name}"
        ).map(&:key)
        if !@visited.intersection(includee_set).empty?
          add_affected_card left_card
          break
        end
      end
    end
  end
end

#each_follower_with_reasonObject



41
42
43
44
45
46
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 41

def each_follower_with_reason
  # "follower"(=user) is a card object, "followed"(=reasons) a card name
  @followed_affected_cards.each do |user, reasons|
    yield(user, reasons.first)
  end
end

#followersObject



37
38
39
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 37

def followers
  @followed_affected_cards.keys
end