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

Extended by:
Card::Set
Defined in:
tmpsets/set/mod017-follow/all/follow/followed_by.rb

Overview

Set: All cards (Follow, FollowedBy)

used by +:followers overwritten in type/set.rb and type/cardtype.rb

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #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 Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



8
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 8

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

Instance Method Details

#all_follow_rule_options(follower_id) ⇒ Object



53
54
55
56
57
58
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 53

def all_follow_rule_options follower_id
  follow_rule = rule :follow, user_id: follower_id
  return [] unless follow_rule.present?

  follow_rule.split("\n")
end

#follow_rule_applies?(follower_id) ⇒ Boolean

the following methods all handle explicit (direct) follow rules (not fields)

Returns:

  • (Boolean)


43
44
45
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 43

def follow_rule_applies? follower_id
  !follow_rule_option(follower_id).nil?
end

#follow_rule_option(follower_id) ⇒ Object



47
48
49
50
51
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 47

def follow_rule_option follower_id
  all_follow_rule_options(follower_id).find do |option|
    follow_rule_option_applies? follower_id, option
  end
end

#follow_rule_option_applies?(follower_id, option) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 60

def follow_rule_option_applies? follower_id, option
  option_code = option.to_name.code
  candidate_ids = follower_candidate_ids_for_option option_code
  follow_rule_option_applies_to_candidates? follower_id, option_code, candidate_ids
end

#follow_rule_option_applies_to_candidates?(follower_id, option_code, candidate_ids) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 66

def follow_rule_option_applies_to_candidates? follower_id, option_code, candidate_ids
  if (test = FollowOption.test[option_code])
    test.call follower_id, candidate_ids
  else
    candidate_ids.include? follower_id
  end
end

#followed?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 9

def followed?
  followed_by? Auth.current_id
end

#followed_by?(user_id) ⇒ Boolean

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)


15
16
17
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 15

def followed_by? user_id
  follow_rule_applies?(user_id) || left&.followed_by_as_field?(self, user_id)
end

#followed_by_as_field?(field, user_id) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 19

def followed_by_as_field? field, user_id
  followed_field?(field) && followed_by?(user_id)
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)


25
26
27
28
29
30
31
32
33
34
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 25

def followed_field? field_card
  return unless (follow_field_rule = rule_card(:follow_fields))

  follow_field_rule.item_names(context: self).find do |item|
    case item.to_name.key
    when field_card.key         then true
    when :includes.cardname.key then nested_card?(field_card)
    end
  end
end

#follower_candidate_ids_for_option(option_code) ⇒ Object



74
75
76
77
78
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 74

def follower_candidate_ids_for_option option_code
  return [] unless (block = FollowOption.follower_candidate_ids[option_code])

  block.call self
end

#nested_card?(card) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'tmpsets/set/mod017-follow/all/follow/followed_by.rb', line 36

def nested_card? card
  @nested_ids ||= includee_ids
  @nested_ids.include? card.id
end