Class: Card::ActManager
- Inherits:
-
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) In all stages except IGwD:
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.
In IGwD all these methods create a new act.
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
-
.act_director ⇒ Object
-
.add(director) ⇒ Object
-
.card(name) ⇒ Object
-
.card_changed(old_card) ⇒ Object
-
.clear ⇒ Object
-
.contextualize_delayed_event(act_id, card, env, auth) ⇒ Object
If active jobs (and hence the integrate_with_delay events) don't run in a background process then Card::Env.deserialize! decouples the controller's params hash and the Card::Env's params hash with the effect that params changes in the CardController get lost (a crucial example are success params that are processed in CardController#soft_redirect).
-
.contextualize_for_delay(act_id, card, env, auth, &block) ⇒ Object
The whole ActManager setup is gone once we reach a integrate with delay event processed by ActiveJob.
-
.deep_delete(director) ⇒ Object
-
.delaying? ⇒ Boolean
-
.delete(director) ⇒ Object
-
.directors ⇒ Object
-
.fetch(card, opts = {}) ⇒ Object
-
.include?(name) ⇒ Boolean
-
.need_act ⇒ Object
-
.new_director(card, opts = {}) ⇒ Object
-
.run_act(card) ⇒ Object
-
.running_act? ⇒ Boolean
-
.to_s ⇒ Object
-
.with_env_and_auth(env, auth) ⇒ Object
Class Method Details
.act_director ⇒ Object
83
84
85
86
|
# File 'lib/card/act_manager.rb', line 83
def act_director
return unless act_card
act_card.director
end
|
.add(director) ⇒ Object
140
141
142
143
|
# File 'lib/card/act_manager.rb', line 140
def add director
directors[director.card] = director
end
|
.card(name) ⇒ Object
134
135
136
137
138
|
# File 'lib/card/act_manager.rb', line 134
def card name
directors.values.find do |dir|
dir.card.name == name
end&.card
end
|
.card_changed(old_card) ⇒ Object
145
146
147
148
|
# File 'lib/card/act_manager.rb', line 145
def card_changed old_card
return unless (director = @directors.delete old_card)
add director
end
|
.clear ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/card/act_manager.rb', line 103
def clear
self.act_card = nil
self.act = nil
directors.each_pair do |card, _dir|
card.director = nil
end
@directors = nil
end
|
.contextualize_delayed_event(act_id, card, env, auth) ⇒ Object
If active jobs (and hence the integrate_with_delay events) don't run
in a background process then Card::Env.deserialize! decouples the
controller's params hash and the Card::Env's params hash with the
effect that params changes in the CardController get lost
(a crucial example are success params that are processed in
CardController#soft_redirect)
173
174
175
176
177
178
179
|
# File 'lib/card/act_manager.rb', line 173
def contextualize_delayed_event act_id, card, env, auth
if delaying?
contextualize_for_delay(act_id, card, env, auth) { yield }
else
yield
end
end
|
.contextualize_for_delay(act_id, card, env, auth, &block) ⇒ Object
The whole ActManager setup is gone once we reach a integrate with delay
event processed by ActiveJob.
This is the improvised resetup to get subcards working.
190
191
192
193
194
195
196
197
198
|
# File 'lib/card/act_manager.rb', line 190
def contextualize_for_delay act_id, card, env, auth, &block
self.act = Act.find act_id if act_id
with_env_and_auth env, auth do
return yield unless act
run_act(act.card || card) do
act_card.director.run_delayed_event act, &block
end
end
end
|
.deep_delete(director) ⇒ Object
156
157
158
159
160
161
|
# File 'lib/card/act_manager.rb', line 156
def deep_delete director
director.subdirectors.each do |subdir|
deep_delete subdir
end
delete director
end
|
.delaying? ⇒ Boolean
181
182
183
184
185
|
# File 'lib/card/act_manager.rb', line 181
def delaying?
const_defined?("Delayed") &&
Delayed::Worker.delay_jobs &&
Card.config.active_job.queue_adapter == :delayed_job
end
|
.delete(director) ⇒ Object
150
151
152
153
154
|
# File 'lib/card/act_manager.rb', line 150
def delete director
return unless @directors
@directors.delete director.card
director.delete
end
|
.directors ⇒ Object
88
89
90
|
# File 'lib/card/act_manager.rb', line 88
def directors
@directors ||= {}
end
|
.fetch(card, opts = {}) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/card/act_manager.rb', line 112
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 && dir_card.director
end
directors[card] = new_director card, opts
end
|
.include?(name) ⇒ Boolean
120
121
122
|
# File 'lib/card/act_manager.rb', line 120
def include? name
directors.keys.any? { |card| card.key == name.to_name.key }
end
|
.need_act ⇒ Object
99
100
101
|
# File 'lib/card/act_manager.rb', line 99
def need_act
self.act ||= Card::Act.create ip_address: Env.ip
end
|
.new_director(card, opts = {}) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/card/act_manager.rb', line 124
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
|
.run_act(card) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/card/act_manager.rb', line 92
def run_act card
self.act_card = card
yield
ensure
clear
end
|
.running_act? ⇒ Boolean
163
164
165
|
# File 'lib/card/act_manager.rb', line 163
def running_act?
(dir = act_director) && dir.running?
end
|
.to_s ⇒ Object
208
209
210
211
|
# File 'lib/card/act_manager.rb', line 208
def to_s
act_director.to_s
end
|
.with_env_and_auth(env, auth) ⇒ Object
200
201
202
203
204
205
206
|
# File 'lib/card/act_manager.rb', line 200
def with_env_and_auth env, auth
Card::Auth.with auth do
Card::Env.with env do
yield
end
end
end
|