Module: Granite::Action::Performing
- Extended by:
- ActiveSupport::Concern
- Includes:
- ExceptionsHandling, Transaction
- Included in:
- Granite::Action
- Defined in:
- lib/granite/action/performing.rb
Overview
Performing module used for defining perform procedure and error handling. Perform procedure is defined as block, which is executed in action instance context so all attributes are available there. Actions by default are performed in silent way (no validation exception raised), to raise exceptions, call bang method #perform!
Defined exceptions handlers are also executed in action instance context, but additionally get raised exception as parameter.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#perform(context: nil, **options) ⇒ Object
deprecated
Deprecated.
Use #perform! or #try_perform! instead
-
#perform!(context: nil, **options) ⇒ Object
Check precondition and validations for action and associated objects, then raise exception in case of validation errors.
-
#performed? ⇒ Boolean
Checks if action was successfully performed or not.
-
#try_perform!(context: nil, **options) ⇒ Object
Performs action if preconditions are satisfied.
Methods included from Transaction
Instance Method Details
#perform(context: nil, **options) ⇒ Object
Use #perform! or #try_perform! instead
Check preconditions and validations for action and associated objects, then in case of valid action run defined procedure. Procedure is wrapped with database transaction. Returns the result of execute_perform! method execution or true if method execution returned false or nil
44 45 46 47 48 49 50 51 52 |
# File 'lib/granite/action/performing.rb', line 44 def perform(context: nil, **) Granite.deprecator.warn('Granite::Action#perform is deprecated, use #perform! or #try_perform! instead') transaction do raise Rollback unless valid?(context) perform_action(**) end end |
#perform!(context: nil, **options) ⇒ Object
Check precondition and validations for action and associated objects, then raise exception in case of validation errors. In other case run defined procedure. Procedure is wraped with database transaction. After procedure execution check for errors, and raise exception if any. Returns the result of execute_perform! method execution or true if block execution returned false or nil
66 67 68 69 70 71 |
# File 'lib/granite/action/performing.rb', line 66 def perform!(context: nil, **) transaction do validate!(context) perform_action!(**) end end |
#performed? ⇒ Boolean
Checks if action was successfully performed or not
93 94 95 |
# File 'lib/granite/action/performing.rb', line 93 def performed? @_action_performed.present? end |
#try_perform!(context: nil, **options) ⇒ Object
Performs action if preconditions are satisfied.
81 82 83 84 85 86 87 88 |
# File 'lib/granite/action/performing.rb', line 81 def try_perform!(context: nil, **) return unless satisfy_preconditions? transaction do validate!(context) perform_action!(**) end end |