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

Extended by:
Card::Set
Defined in:
platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb

Overview

Set: All cards (Follow, FollowerIds)

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

FOLLOWER_IDS_CACHE_KEY =
"FOLLOWER_IDS".freeze

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset

Methods included from I18nScope

#mod_name, #scope

Methods included from Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from Card::Set::AdvancedApi

#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/mod/follow/set/all/follow/follower_ids.rb"; end

Instance Method Details

#direct_follower_ids(&block) ⇒ Object



102
103
104
105
106
107
108
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 102

def direct_follower_ids &block
  ids = ::Set.new
  set_names.each do |set_name|
    direct_follower_ids_for_set setcard_from_name(set_name), ids, &block
  end
  ids
end

#direct_follower_ids_for_set(set_card, ids) ⇒ Object



114
115
116
117
118
119
120
121
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 114

def direct_follower_ids_for_set set_card, ids
  set_card.all_user_ids_with_rule_for(:follow).each do |user_id|
    next if ids.include?(user_id) || !(option = follow_rule_option user_id)

    yield user_id, set_card, option if block_given?
    ids << user_id
  end
end

#direct_followersObject

all users (cards) that “directly” follow this card “direct” means there is a follow rule that applies explicitly to this card. one can also “indirectly” follow cards by following parent cards or other cards that nest this one.



96
97
98
99
100
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 96

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

#each_direct_follower_id_with_reasonObject



123
124
125
126
127
128
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 123

def each_direct_follower_id_with_reason
  direct_follower_ids do |user_id, set_card, follow_option|
    reason = follow_option.gsub(/[\[\]]/, "")
    yield user_id, set_card: set_card, option: reason
  end
end

#event: cache_expired_for_type_changeObject



12
13
14
15
16
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 12

event :cache_expired_for_type_change, :store, on: :update, changed: %i[type_id name] do
  act_card&.schedule_preference_expiration
  # FIXME: expire (also?) after save
  Card.follow_caches_expired
end

#event: expire_preferences_cacheObject



26
27
28
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 26

event :expire_preferences_cache, :finalize, when: :expire_preferences? do
  Card::Rule.clear_preference_cache
end

#expire_preferences?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 22

def expire_preferences?
  @expire_preferences_scheduled
end

#follower_idsObject



70
71
72
73
74
75
76
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 70

def follower_ids
  @follower_ids = read_follower_ids_cache || begin
    result = direct_follower_ids + indirect_follower_ids
    write_follower_ids_cache result
    result
  end
end

#follower_namesObject



60
61
62
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 60

def follower_names
  followers.map(&:name)
end

#followersObject



64
65
66
67
68
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 64

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

#followers_countObject



78
79
80
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 78

def followers_count
  follower_ids.size
end

#indirect_follower_idsObject



82
83
84
85
86
87
88
89
90
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 82

def indirect_follower_ids
  result = ::Set.new
  left_card = left
  while left_card
    result += left_card.direct_follower_ids if left_card.followed_field? self
    left_card = left_card.left
  end
  result
end

#read_follower_ids_cacheObject



56
57
58
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 56

def read_follower_ids_cache
  Card.follower_ids_cache[id]
end

#schedule_preference_expirationObject



18
19
20
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 18

def schedule_preference_expiration
  @expire_preferences_scheduled = true
end

#setcard_from_name(set_name) ⇒ Object



110
111
112
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 110

def setcard_from_name set_name
  Card.fetch set_name, new: { type_id: SetID }
end

#write_follower_ids_cache(user_ids) ⇒ Object



50
51
52
53
54
# File 'platypus/tmp/set/gem-defaults/mod028-follow/all/follow/follower_ids.rb', line 50

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