Module: Card::Set::All::Phases
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod001-01_core/all/phases.rb
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file
Instance Method Details
#abort(status, msg = 'action canceled') ⇒ Object
The Card#abort method is for cleanly exiting an action without continuing to process any further events.
Three statuses are supported:
failure: adds an error, returns false on save
success: no error, returns true on save
triumph: similar to success, but if called on a subcard it causes the entire action to abort (not just the subcard)
12
13
14
15
16
17
18
19
20
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 12
def abort status, msg='action canceled'
if status == :failure && errors.empty?
errors.add :abort, msg
elsif Hash === status and status[:success]
success << status[:success]
status = :success
end
raise Card::Abort.new( status, msg)
end
|
#abortable ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 23
def abortable
yield
rescue Card::Abort => e
if e.status == :triumph
@supercard ? raise( e ) : true
elsif e.status == :success
if @supercard
@supercard.subcards.delete_if { |k,v| v==self }
end
true
end
end
|
64
65
66
67
68
69
70
71
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 64
def approve
@action ||= identify_action
run_callbacks :approve
expire_pieces if errors.any?
errors.empty?
rescue =>e
rescue_event e
end
|
#changed_condition_applies?(db_column) ⇒ Boolean
139
140
141
142
143
144
145
146
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 139
def changed_condition_applies? db_column
if db_column
db_column = 'db_content' if db_column.to_sym == :content
@action != :delete && changes[db_column.to_s]
else
true
end
end
|
#event_applies?(opts) ⇒ Boolean
125
126
127
128
129
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 125
def event_applies? opts
on_condition_applies?(opts[:on]) &&
changed_condition_applies?(opts[:changed]) &&
when_condition_applies?(opts[:when])
end
|
95
96
97
98
99
100
101
102
103
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 95
def extend
run_callbacks :extend
run_callbacks :subsequent
rescue =>e
rescue_event e
ensure
@action = nil
end
|
#identify_action ⇒ Object
73
74
75
76
77
78
79
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 73
def identify_action
case
when trash ; :delete
when new_card? ; :create
else :update
end
end
|
#on_condition_applies?(action) ⇒ Boolean
131
132
133
134
135
136
137
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 131
def on_condition_applies? action
if action
Array.wrap(action).member? @action
else
true
end
end
|
perhaps above should be in separate module? ~~~~~~
54
55
56
57
58
59
60
61
62
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 54
def prepare
@action = identify_action
reset_patterns
include_set_modules
run_callbacks :prepare
rescue =>e
rescue_event e
end
|
#rescue_event(e) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 108
def rescue_event e
@action = nil
expire_pieces
subcards.each do |key, card|
next unless Card===card
card.expire_pieces
end
raise e
end
|
82
83
84
85
86
87
88
89
90
91
92
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 82
def store
run_callbacks :store do
yield @virtual = false
end
run_callbacks :stored
rescue =>e
rescue_event e
ensure
@from_trash = @last_action_id = @last_content_action_id = nil
end
|
157
158
159
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 157
def subcards
@subcards ||= {}
end
|
208
209
210
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 208
def success
Env.success(cardname)
end
|
#valid_subcard? ⇒ Boolean
36
37
38
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 36
def valid_subcard?
abortable { valid? }
end
|
#when_condition_applies?(block) ⇒ Boolean
148
149
150
151
152
153
154
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 148
def when_condition_applies? block
if block
block.call self
else
true
end
end
|
#with_transaction_returning_status ⇒ Object
this is an override of standard rails behavior that rescues abortmakes it so that :success abortions do not rollback
41
42
43
44
45
46
47
48
49
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 41
def with_transaction_returning_status
status = nil
self.class.transaction do
add_to_transaction
status = abortable { yield }
raise ActiveRecord::Rollback unless status
end
status
end
|