Module: Card::Subcards::Remove

Included in:
Card::Subcards
Defined in:
card/lib/card/subcards/remove.rb

Overview

Methods for removing/clearing subcards

Instance Method Summary collapse

Instance Method Details

#clearObject



19
20
21
22
# File 'card/lib/card/subcards/remove.rb', line 19

def clear
  @keys.each { |key| clear_key key }
  @keys = ::Set.new
end

#clear_key(key) ⇒ Object



24
25
26
27
28
29
30
31
# File 'card/lib/card/subcards/remove.rb', line 24

def clear_key key
  if (subcard = fetch_subcard key)
    Director.deep_delete subcard.director
    subcard.current_action&.delete
  end
  Card.cache.temp.delete key
  subcard
end

#deep_clear(cleared = ::Set.new) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'card/lib/card/subcards/remove.rb', line 33

def deep_clear cleared=::Set.new
  each_card do |card|
    next if cleared.include? card.id

    cleared << card.id
    card.subcards.deep_clear cleared
  end
  clear
end

#remove(name_or_card) ⇒ Object



11
12
13
14
15
16
17
# File 'card/lib/card/subcards/remove.rb', line 11

def remove name_or_card
  key = subcard_key name_or_card
  return unless @keys.include? key

  @keys.delete key
  clear_key key
end

#remove_child(cardish) ⇒ Object Also known as: remove_field



5
6
7
8
# File 'card/lib/card/subcards/remove.rb', line 5

def remove_child cardish
  child = cardish.is_a?(Card) ? cardish : child(cardish)
  remove child
end