Module: Card::Director::ActDirection

Included in:
Card::Director
Defined in:
card/lib/card/director/act_direction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actObject

Returns the value of attribute act.



4
5
6
# File 'card/lib/card/director/act_direction.rb', line 4

def act
  @act
end

#act_cardObject

Returns the value of attribute act_card.



4
5
6
# File 'card/lib/card/director/act_direction.rb', line 4

def act_card
  @act_card
end

Instance Method Details

#act_directorObject



6
7
8
9
10
# File 'card/lib/card/director/act_direction.rb', line 6

def act_director
  return unless act_card

  act_card.director
end

#add(director) ⇒ Object



81
82
83
84
# File 'card/lib/card/director/act_direction.rb', line 81

def add director
  # Rails.logger.debug "added: #{director.card.name}".green
  directors[director.card] = director
end

#card(name) ⇒ Object



75
76
77
78
79
# File 'card/lib/card/director/act_direction.rb', line 75

def card name
  directors.values.find do |dir|
    dir.card.name == name
  end&.card
end

#card_changed(old_card) ⇒ Object



86
87
88
89
90
# File 'card/lib/card/director/act_direction.rb', line 86

def card_changed old_card
  return unless (director = @directors.delete old_card)

  add director
end

#clearObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'card/lib/card/director/act_direction.rb', line 28

def clear
  self.act_card = nil
  self.act = nil
  directors.each_pair do |card, _dir|
    card.expire
    card.director = nil
    card.action = nil
    card.clear_action_specific_attributes
  end
  expire
  @directors = nil
end

#deep_delete(director) ⇒ Object



99
100
101
102
103
104
# File 'card/lib/card/director/act_direction.rb', line 99

def deep_delete director
  director.subdirectors.each do |subdir|
    deep_delete subdir
  end
  delete director
end

#delete(director) ⇒ Object



92
93
94
95
96
97
# File 'card/lib/card/director/act_direction.rb', line 92

def delete director
  return unless @directors

  @directors.delete director.card
  director.delete
end

#directorsObject



12
13
14
# File 'card/lib/card/director/act_direction.rb', line 12

def directors
  @directors ||= {}
end

#expireObject



41
42
43
44
# File 'card/lib/card/director/act_direction.rb', line 41

def expire
  expirees.each { |expiree| Card.expire expiree }
  @expirees = []
end

#expireesObject



46
47
48
# File 'card/lib/card/director/act_direction.rb', line 46

def expirees
  @expirees ||= []
end

#fetch(card, parent = nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'card/lib/card/director/act_direction.rb', line 50

def fetch card, parent=nil
  return directors[card] if directors[card]

  directors.each_key do |dir_card|
    return dir_card.director if dir_card.name == card.name && dir_card.director
  end
  add new_director(card, parent)
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'card/lib/card/director/act_direction.rb', line 59

def include? name
  directors.keys.any? { |card| card.key == name.to_name.key }
end

#include_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'card/lib/card/director/act_direction.rb', line 63

def include_id? id
  directors.keys.any? { |card| card.id == id }
end

#need_actObject



24
25
26
# File 'card/lib/card/director/act_direction.rb', line 24

def need_act
  self.act ||= Card::Act.create ip_address: Env.ip
end

#new_director(card, parent) ⇒ Object



67
68
69
70
71
72
73
# File 'card/lib/card/director/act_direction.rb', line 67

def new_director card, parent
  if !parent && act_card && act_card != card && running_act?
    act_card.director.subdirectors.add card
  else
    Director.new card, parent
  end
end

#run_act(card) ⇒ Object



16
17
18
19
20
21
22
# File 'card/lib/card/director/act_direction.rb', line 16

def run_act card
  self.act_card = card
  # add new_director(card)
  yield
ensure
  clear
end

#running_act?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'card/lib/card/director/act_direction.rb', line 106

def running_act?
  act_director&.running?
end

#to_sObject



110
111
112
# File 'card/lib/card/director/act_direction.rb', line 110

def to_s
  act_director.to_s
end