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

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

Instance Method Summary collapse

Constructor Details

#initialize(card = nil) ⇒ FollowerStash

Returns a new instance of FollowerStash.



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

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



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

def add_affected_card card
  Auth.as_bot do
    if !@visited.include? card.key
      @visited.add card.key
      card.all_direct_follower_ids_with_reason do |user_id, reason|
        notify Card.fetch(user_id), :of=>reason
      end
      if card.left and !@visited.include?(card.left.name) and follow_field_rule = card.left.rule_card(:follow_fields)

        follow_field_rule.item_names(:context=>card.left.cardname).each do |item|
          if @visited.include? item.to_name.key
            add_affected_card card.left
            break
          elsif item.to_name.key == Card[:includes].key
            includee_set = Card.search(:included_by=>card.left.name).map(&:key)
            if !@visited.intersection(includee_set).empty?
              add_affected_card card.left
              break
            end
          end
        end

      end

    end

  end
end

#each_follower_with_reasonObject

“follower” is a card object, “followed” a card name



44
45
46
47
48
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 44

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

#followersObject



40
41
42
# File 'tmpsets/set/mod006-05_email/all/notify.rb', line 40

def followers
  @followed_affected_cards.keys
end