Module: TurboBoost::Commands::CommandCallbacks
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveSupport::Callbacks, ActiveSupport::Rescuable, Observable
- Included in:
- Command
- Defined in:
- lib/turbo_boost/commands/command_callbacks.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- NAME =
:perform_command
Instance Method Summary collapse
- #abort_handler(error = nil) ⇒ Object
- #aborted? ⇒ Boolean
- #error_handler(error) ⇒ Object
- #errored? ⇒ Boolean
- #perform_with_callbacks(method_name) ⇒ Object
- #performed? ⇒ Boolean
- #performing? ⇒ Boolean
- #succeeded? ⇒ Boolean
Instance Method Details
#abort_handler(error = nil) ⇒ Object
133 134 135 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 133 def abort_handler(error = nil) # noop, override in subclasses via `on_abort` end |
#aborted? ⇒ Boolean
113 114 115 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 113 def aborted? !!@aborted end |
#error_handler(error) ⇒ Object
137 138 139 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 137 def error_handler(error) # noop, override in subclasses via `on_error` end |
#errored? ⇒ Boolean
117 118 119 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 117 def errored? !!@errored end |
#perform_with_callbacks(method_name) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 88 def perform_with_callbacks(method_name) # Setup a temporary `rescue_from` handler on the controller to trap command errors because commands are # run in a controller `before_action` callback. This allows us to properly handle command errors here # instead of letting Rails return the normal 500 error page. command = self controller.class.rescue_from Exception, with: ->(error) { command.send :internal_error_handler, error } @performing_method_name = method_name begin run_callbacks NAME do public_send method_name performed! end ensure @performing_method_name = nil end # Tear down the temporary `rescue_from` handler controller.rescue_handlers.reject! do |handler| handler.to_s.include? "turbo_boost/commands/command_callbacks.rb" end rescue => error internal_error_handler error end |
#performed? ⇒ Boolean
125 126 127 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 125 def performed? !!@performed end |
#performing? ⇒ Boolean
121 122 123 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 121 def performing? !!@performing_method_name end |
#succeeded? ⇒ Boolean
129 130 131 |
# File 'lib/turbo_boost/commands/command_callbacks.rb', line 129 def succeeded? performed? && !aborted? && !errored? end |