Module: Card::Director::ClassMethods

Includes:
EventDelay
Included in:
Card::Director
Defined in:
lib/card/director/class_methods.rb

Overview

Card::Director class methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventDelay

#contextualize_delayed_event, #delaying?, #run_job_with_act, #with_delay_act, #with_env_and_auth

Instance Attribute Details

#actObject

Returns the value of attribute act.



7
8
9
# File 'lib/card/director/class_methods.rb', line 7

def act
  @act
end

#act_cardObject

Returns the value of attribute act_card.



7
8
9
# File 'lib/card/director/class_methods.rb', line 7

def act_card
  @act_card
end

Instance Method Details

#act_directorObject



9
10
11
# File 'lib/card/director/class_methods.rb', line 9

def act_director
  act_card&.director
end

#add(director) ⇒ Object



83
84
85
86
# File 'lib/card/director/class_methods.rb', line 83

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

#card(name) ⇒ Object



77
78
79
80
81
# File 'lib/card/director/class_methods.rb', line 77

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

#card_changed(old_card) ⇒ Object



88
89
90
91
92
# File 'lib/card/director/class_methods.rb', line 88

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

  add director
end

#clearObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/card/director/class_methods.rb', line 31

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

#deep_delete(director) ⇒ Object



102
103
104
105
106
107
# File 'lib/card/director/class_methods.rb', line 102

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

#delete(director) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/card/director/class_methods.rb', line 94

def delete director
  return unless @directors

  # normal delete was sometimes failing here (eg. when aborting in finalize stage)
  @directors.delete_if { |k, _v| k == director.card }
  director.delete
end

#directorsObject



13
14
15
# File 'lib/card/director/class_methods.rb', line 13

def directors
  @directors ||= {}
end

#expireObject



43
44
45
46
# File 'lib/card/director/class_methods.rb', line 43

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

#expireesObject



48
49
50
# File 'lib/card/director/class_methods.rb', line 48

def expirees
  @expirees ||= []
end

#fetch(card, parent = nil) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/card/director/class_methods.rb', line 52

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)


61
62
63
# File 'lib/card/director/class_methods.rb', line 61

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

#include_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/card/director/class_methods.rb', line 65

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

#need_actObject



27
28
29
# File 'lib/card/director/class_methods.rb', line 27

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

#new_director(card, parent) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/card/director/class_methods.rb', line 69

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



17
18
19
20
21
22
23
24
25
# File 'lib/card/director/class_methods.rb', line 17

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

#running_act?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/card/director/class_methods.rb', line 109

def running_act?
  act_director&.running?
end

#to_sObject



113
114
115
# File 'lib/card/director/class_methods.rb', line 113

def to_s
  act_director.to_s
end