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, 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
|
#event_applies?(opts) ⇒ Boolean
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 124
def event_applies? opts
if opts[:on]
return false unless Array.wrap( opts[:on] ).member? @action
end
if changed_field = opts[:changed]
changed_field = 'db_content' if changed_field.to_sym == :content
return false if @action == :delete or !changes[ changed_field.to_s ]
end
if opts[:when]
return false unless opts[:when].call self
end
true
end
|
95
96
97
98
99
100
101
102
|
# 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
|
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
107
108
109
110
111
112
113
114
115
116
117
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 107
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
|
139
140
141
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 139
def subcards
@subcards ||= {}
end
|
190
191
192
|
# File 'tmpsets/set/mod001-01_core/all/phases.rb', line 190
def success
Env[:success] ||= Card::Success.new(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
|
#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
|