Class: Granite::Action

Inherits:
Object
  • Object
show all
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/types/collection.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, Types Classes: Error, NotAllowedError, Precondition, Rollback, SubjectNotFoundError, SubjectTypeMismatchError, ValidationError

Instance Attribute Summary

Attributes included from Preconditions

#failed_preconditions

Instance Method Summary collapse

Methods included from Policies

#allowed?, #authorize!, #perform, #perform!, #try_perform!

Methods included from Preconditions

#decline_with, #initialize, #satisfy_preconditions?

Methods included from Performer

#initialize

Methods included from Subject

#initialize

Methods included from Performing

#perform, #perform!, #performed?, #try_perform!

Methods included from Transaction

#run_callbacks

Methods included from Translations

#translate

Methods included from Util

#conditions_satisfied?, #evaluate

Methods included from AssignAttributes

#assign_attributes

Methods included from Instrumentation

#perform, #perform!, #try_perform!

Instance Method Details

#attributes_changed?(except: []) ⇒ Boolean

Almost the same as Dirty ‘#changed?` method, but doesn’t check subject reference key

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/granite/action.rb', line 82

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



67
68
69
70
71
# File 'lib/granite/action.rb', line 67

def merge_errors(other_errors)
  errors.messages.deep_merge!(other_errors.messages) 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

Returns:

  • (Boolean)

    whether action is performable



91
92
93
94
# File 'lib/granite/action.rb', line 91

def performable?
  @performable = allowed? && satisfy_preconditions? unless instance_variable_defined?(:@performable)
  @performable
end