Module: Foobara::CommandPatternImplementation::Concerns::Runtime
- Includes:
- Foobara::Concern
- Included in:
- Foobara::CommandPatternImplementation
- Defined in:
- foobara-0.2.7/projects/command/src/command_pattern_implementation/concerns/runtime.rb
Defined Under Namespace
Modules: ClassMethods Classes: CannotHaltWithoutAddingErrors, Halt, NotFoundError
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#raw_result ⇒ Object
Returns the value of attribute raw_result.
Instance Method Summary collapse
Methods included from Foobara::Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
27 28 29 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 27 def exception @exception end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
27 28 29 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 27 def outcome @outcome end |
#raw_result ⇒ Object
Returns the value of attribute raw_result.
28 29 30 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 28 def raw_result @raw_result end |
Instance Method Details
#halt! ⇒ Object
77 78 79 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 77 def halt! raise Halt end |
#run ⇒ Object
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 65 66 67 68 69 70 71 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 34 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? # :nocov: raise CannotHaltWithoutAddingErrors, "Cannot halt without adding errors first. " \ "Either add errors or use error! transition instead." # :nocov: end state_machine.fail! @outcome = Outcome.errors(error_collection) rescue => e @exception = e rollback_transaction state_machine.error! raise end |
#run! ⇒ Object
30 31 32 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 30 def run! run.result! end |
#success? ⇒ Boolean
73 74 75 |
# File 'projects/command/src/command_pattern_implementation/concerns/runtime.rb', line 73 def success? outcome&.success? end |