Module: Card::Set::Right::Read

Extended by:
Card::Set
Includes:
Abstract::Permission
Defined in:
card/tmpsets/set/mod010-card-mod-permissions/right/read.rb,
card/tmpsets/set/mod009-card-mod-permissions/right/read.rb

Overview

Set: All “+Read” cards

Constant Summary

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_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 AdvancedApi

#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 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

Methods included from Abstract::Permission

#options_rule_card, #standardize_items

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-permissions/set/right/read.rb"; end

Instance Method Details

#all_membersObject



62
63
64
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 62

def all_members
  rule_set.item_cards limit: 0
end

#each_member(&block) ⇒ Object



54
55
56
57
58
59
60
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 54

def each_member
  Auth.as_bot do
    all_members.each_with_object(::Set.new) do |member, processed|
      yield member, processed
    end
  end
end

#event: cascade_read_ruleObject



12
13
14
15
16
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 12

event :cascade_read_rule, :finalize, after: :update_rule_cache, when: :is_rule? do
  return unless name_is_changing? || trash_is_changing?

  update_read_ruled_cards
end

#event: process_read_rule_update_queueObject



84
85
86
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 84

event :process_read_rule_update_queue, :finalize do
  left&.update_read_rule
end

#invalid_pattern_id(pattern_id) ⇒ Object



80
81
82
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 80

def invalid_pattern_id pattern_id
  Rails.logger.info "invalid pattern id for read rule: #{pattern_id}"
end

#member_has_overriding_rule?(member) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 38

def member_has_overriding_rule? member
  pattern_index(Card.fetch_id(member.read_rule_class)) < rule_pattern_index
end

#pattern_idsObject



76
77
78
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 76

def pattern_ids
  @pattern_ids ||= set_patterns.map(&:pattern_id)
end

#pattern_index(pattern_id) ⇒ Object



72
73
74
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 72

def pattern_index pattern_id
  pattern_ids.index(pattern_id) || invalid_pattern_id(pattern_id)
end

#rule_pattern_indexObject



66
67
68
69
70
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 66

def rule_pattern_index
  return if trash

  @rule_pattern_index ||= pattern_index rule_set&.tag&.id
end

#update_cards_with_read_rule_id(processed) ⇒ Object

cards with this card as a read_rule_id These may include cards that are no longer set members if the card was renamed (edge case)



45
46
47
48
49
50
51
52
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 45

def update_cards_with_read_rule_id processed
  processed ||= ::Set.new
  Card::Auth.as_bot do
    Card.search(read_rule_id: id) do |card|
      card.update_read_rule unless processed.include?(card.key)
    end
  end
end

#update_read_ruled_cardsObject



18
19
20
21
22
23
24
25
26
27
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 18

def update_read_ruled_cards
  Card::Rule.clear_read_rule_cache
  Card.cache.reset # maybe be more surgical, just Auth.user related
  expire # probably shouldn't be necessary,
  # but was sometimes getting cached version when card should be in the
  # trash.  could be related to other bugs?

  processed = update_read_rules_of_set_members
  update_cards_with_read_rule_id processed unless new?
end

#update_read_rules_of_set_membersObject



29
30
31
32
33
34
35
36
# File 'card/tmpsets/set/mod010-card-mod-permissions/right/read.rb', line 29

def update_read_rules_of_set_members
  return unless rule_pattern_index

  each_member do |member, processed|
    processed << member.key
    member.update_read_rule unless member_has_overriding_rule?(member)
  end
end