Class: Card::ActManager

Inherits:
Object
  • Object
show all
Defined in:
lib/card/act_manager.rb,
lib/card/act_manager/stage.rb,
lib/card/act_manager/stage_director.rb,
lib/card/act_manager/subdirector_array.rb,
lib/card/act_manager/stage_director/phases.rb

Overview

available values: dirty attributes yes | yes | yes params yes | yes | yes success yes | yes | yes no session yes | yes | yes no

Explanation: yes! the recommended stage to do that yes ok to do it here no not recommended; chance to mess things up but if something forces you to do it here you can try no! never do it here. it won't work or will break things

if there is only a single entry in a phase column it counts for all stages of that phase

1) 'insecure' means a change of a card attribute that can possibly make the card invalid to save 2) 'secure' means you are sure that the change doesn't affect the validation 3) If you call 'create', 'update_attributes' or 'save' the card will become part of the same act and all stage of the validation and storage phase will be executed immediately for that card. The integration phase will be executed together with the act card and its subcards 4) This means if an exception is raised in the validation or storage phase everything will rollback. If the integration phase fails the db changes of the other two phases will remain persistent.

Defined Under Namespace

Modules: Stage Classes: StageDirector, StageSubdirector, SubdirectorArray

Class Method Summary collapse

Class Method Details

.act_directorObject



80
81
82
83
# File 'lib/card/act_manager.rb', line 80

def act_director
  return unless act_card
  act_card.director
end

.add(director) ⇒ Object



119
120
121
122
# File 'lib/card/act_manager.rb', line 119

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

.card_changed(old_card) ⇒ Object



124
125
126
127
# File 'lib/card/act_manager.rb', line 124

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

.clearObject



89
90
91
92
93
94
95
# File 'lib/card/act_manager.rb', line 89

def clear
  ActManager.act_card = nil
  directors.each_pair do |card, _dir|
    card.director = nil
  end
  @directors = nil
end

.deep_delete(director) ⇒ Object



135
136
137
138
139
140
# File 'lib/card/act_manager.rb', line 135

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

.delete(director) ⇒ Object



129
130
131
132
133
# File 'lib/card/act_manager.rb', line 129

def delete director
  return unless @directors
  @directors.delete director.card
  director.delete
end

.directorsObject



85
86
87
# File 'lib/card/act_manager.rb', line 85

def directors
  @directors ||= {}
end

.fetch(card, opts = {}) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/card/act_manager.rb', line 97

def fetch card, opts={}
  return directors[card] if directors[card]
  directors.each_key do |dir_card|
    return dir_card.director if dir_card.name == card.name
  end
  directors[card] = new_director card, opts
end

.include?(name) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/card/act_manager.rb', line 105

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

.new_director(card, opts = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/card/act_manager.rb', line 109

def new_director card, opts={}
  if opts[:parent]
    StageSubdirector.new card, opts
  elsif act_card && act_card != card && running_act?
    act_card.director.subdirectors.add card
  else
    StageDirector.new card
  end
end

.running_act?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/card/act_manager.rb', line 142

def running_act?
  (dir = act_director) && dir.running?
end

.to_sObject



146
147
148
149
# File 'lib/card/act_manager.rb', line 146

def to_s
  act_director.to_s
  #directors.values.map(&:to_s).join "\n"
end