class Card::FollowerStash

stash followers of a given card

Public Class Methods

new(card=nil) click to toggle source
# File lib/card/follower_stash.rb, line 4
def initialize card=nil
  @stash = Hash.new { |h, v| h[v] = [] }
  @checked = ::Set.new
  check_card(card) if card
end

Public Instance Methods

check_card(card) click to toggle source
# File lib/card/follower_stash.rb, line 10
def check_card card
  return if @checked.include? card.key

  Auth.as_bot do
    @checked.add card.key
    stash_direct_followers card
    stash_field_followers card.left
  end
end
each_follower_with_reason() { |follower_card, first| ... } click to toggle source
# File lib/card/follower_stash.rb, line 24
def each_follower_with_reason
  # "follower"(=user) is a card object, "followed"(=reasons) a card name
  @stash.each do |follower_card, reasons|
    yield(follower_card, reasons.first)
  end
end
followers() click to toggle source
# File lib/card/follower_stash.rb, line 20
def followers
  @stash.keys
end

Private Instance Methods

checked?(name) click to toggle source
# File lib/card/follower_stash.rb, line 74
def checked? name
  @checked.include? name.key
end
follow_fields(card) click to toggle source
# File lib/card/follower_stash.rb, line 78
def follow_fields card
  return unless card && !checked?(card.name)

  card.rule_card(:follow_fields)&.item_names(context: card.name)
end
includes_card_key() click to toggle source
# File lib/card/follower_stash.rb, line 60
def includes_card_key
  @includes_card_key ||= :nests.cardname.key
end
nested?(card, field) click to toggle source
# File lib/card/follower_stash.rb, line 54
def nested? card, field
  return unless field.to_name.key == includes_card_key

  @checked.intersection(nestee_set(card)).any?
end
nestee_set(card) click to toggle source
# File lib/card/follower_stash.rb, line 64
def nestee_set card
  @nestee_set ||= {}
  @nestee_set[card.key] ||= nestee_search card
end
stash(follower, reason) click to toggle source
# File lib/card/follower_stash.rb, line 84
def stash follower, reason
  @stash[follower] << reason
end
stash_direct_followers(card) click to toggle source
# File lib/card/follower_stash.rb, line 33
def stash_direct_followers card
  card.each_direct_follower_id_with_reason do |user_id, reason|
    stash Card.fetch(user_id), reason
  end
end
stash_field_follower(card, field) click to toggle source
# File lib/card/follower_stash.rb, line 47
def stash_field_follower card, field
  return false unless checked?(field.to_name) || nested?(card, field)

  check_card card
  true
end
stash_field_followers(card) click to toggle source
# File lib/card/follower_stash.rb, line 39
def stash_field_followers card
  return unless (fields = follow_fields card)

  fields.each do |field|
    break if stash_field_follower card, field
  end
end