Class: Granite::Action
- Inherits:
-
Object
- Object
- Granite::Action
- Includes:
- AssignAttributes, Instrumentation, Performer, Performing, Policies, Preconditions, Projectors, Subject, Translations, Base
- Defined in:
- lib/granite/action.rb,
lib/granite/action/error.rb,
lib/granite/action/subject.rb,
lib/granite/action/policies.rb,
lib/granite/action/performer.rb,
lib/granite/action/performing.rb,
lib/granite/action/projectors.rb,
lib/granite/action/transaction.rb,
lib/granite/action/precondition.rb,
lib/granite/action/translations.rb,
lib/granite/action/preconditions.rb,
lib/granite/action/instrumentation.rb,
lib/granite/action/exceptions_handling.rb,
lib/granite/action/transaction_manager.rb,
lib/granite/action/policies/any_strategy.rb,
lib/granite/action/policies/always_allow_strategy.rb,
lib/granite/action/preconditions/base_precondition.rb,
lib/granite/action/preconditions/object_precondition.rb,
lib/granite/action/preconditions/embedded_precondition.rb,
lib/granite/action/policies/required_performer_strategy.rb,
lib/granite/action/transaction_manager/transactions_stack.rb
Defined Under Namespace
Modules: AssignAttributes, ExceptionsHandling, Instrumentation, Performer, Performing, Policies, Preconditions, Projectors, Subject, Transaction, TransactionManager, Translations Classes: Error, NotAllowedError, Precondition, Rollback, SubjectNotFoundError, SubjectTypeMismatchError, ValidationError
Instance Attribute Summary
Attributes included from Preconditions
Instance Method Summary collapse
-
#attributes_changed?(except: []) ⇒ Boolean
Almost the same as Dirty ‘#changed?` method, but doesn’t check subject reference key.
-
#initialize ⇒ Action
constructor
A new instance of Action.
- #merge_errors(other_errors) ⇒ Object
-
#performable? ⇒ Boolean
Check if action is allowed to execute by current performer (see performer) and satisfy all defined preconditions.
Methods included from Policies
#allowed?, #authorize!, #perform, #perform!, #try_perform!
Methods included from Preconditions
#decline_with, #satisfy_preconditions?
Methods included from Performing
#perform, #perform!, #performed?, #try_perform!
Methods included from Transaction
Methods included from Translations
Methods included from AssignAttributes
Methods included from Instrumentation
#perform, #perform!, #try_perform!
Constructor Details
#initialize ⇒ Action
Returns a new instance of Action.
67 68 69 70 |
# File 'lib/granite/action.rb', line 67 def initialize(*) super _run_initialize_callbacks end |
Instance Method Details
#attributes_changed?(except: []) ⇒ Boolean
Almost the same as Dirty ‘#changed?` method, but doesn’t check subject reference key
88 89 90 91 |
# File 'lib/granite/action.rb', line 88 def attributes_changed?(except: []) except = Array.wrap(except).push(self.class.reflect_on_association(:subject).reference_key) changed_attributes.except(*except).present? end |
#merge_errors(other_errors) ⇒ Object
73 74 75 76 77 |
# File 'lib/granite/action.rb', line 73 def merge_errors(other_errors) errors..deep_merge!(other_errors.) do |_, this, other| (this + other).uniq end end |
#performable? ⇒ Boolean
Check if action is allowed to execute by current performer (see Granite.performer) and satisfy all defined preconditions
97 98 99 100 |
# File 'lib/granite/action.rb', line 97 def performable? @performable = allowed? && satisfy_preconditions? unless instance_variable_defined?(:@performable) @performable end |