Module: Foobara::CommandPatternImplementation::Concerns::Runtime
Defined Under Namespace
Modules: ClassMethods
Classes: CannotHaltWithoutAddingErrors, Halt
Instance Attribute Summary collapse
Instance Method Summary
collapse
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception.
20
21
22
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 20
def exception
@exception
end
|
#outcome ⇒ Object
Returns the value of attribute outcome.
20
21
22
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 20
def outcome
@outcome
end
|
#raw_result ⇒ Object
Returns the value of attribute raw_result.
21
22
23
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 21
def raw_result
@raw_result
end
|
Instance Method Details
#execute ⇒ Object
76
77
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 76
def execute
end
|
#halt! ⇒ Object
91
92
93
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 91
def halt!
raise Halt
end
|
#run ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 27
def run
Foobara::Namespace.use self.class do
invoke_with_callbacks_and_transition(:open_transaction)
invoke_with_callbacks_and_transition_in_transaction([
:cast_and_validate_inputs,
:load_records,
:validate_records,
:validate,
:run_execute,
:commit_transaction
])
invoke_with_callbacks_and_transition(:succeed)
end
@outcome
rescue Halt
rollback_transaction
return outcome if state_machine.currently_errored?
if error_collection.empty?
raise CannotHaltWithoutAddingErrors, "Cannot halt without adding errors first. " \
"Either add errors or use error! transition instead."
end
state_machine.fail!
@outcome = Outcome.errors(error_collection)
rescue => e
@exception = e
rollback_transaction
state_machine.error!
raise
end
|
#run! ⇒ Object
23
24
25
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 23
def run!
run.result!
end
|
#run_execute ⇒ Object
70
71
72
73
74
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 70
def run_execute
self.raw_result = execute
result = process_result_using_result_type(raw_result)
@outcome = Outcome.success(result)
end
|
#succeed ⇒ Object
79
80
81
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 79
def succeed
end
|
#success? ⇒ Boolean
66
67
68
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 66
def success?
outcome&.success?
end
|
#validate ⇒ Object
87
88
89
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 87
def validate
end
|
#validate_records ⇒ Object
83
84
85
|
# File 'foobara-0.0.130/projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 83
def validate_records
end
|