module Granite::Action::Preconditions

Conditions module is used to define preconditions for actions. Each precondition is also defined as validation, so it always run before action execution. Precondition name is by default I18n key for :base error, if precondition fails. Along with preconditions question methods with the same names are created.

Attributes

failed_preconditions[R]

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/granite/action/preconditions.rb, line 86
def initialize(*)
  @failed_preconditions = []
  super
end

Public Instance Methods

decline_with(*args) click to toggle source

Adds passed error message and options to `errors` object

# File lib/granite/action/preconditions.rb, line 101
def decline_with(*args)
  errors.add(:base, *args)
  failed_preconditions << args.first
end
satisfy_preconditions?() click to toggle source

Check if all preconditions are satisfied

@return [Boolean] wheter all preconditions are satisfied

# File lib/granite/action/preconditions.rb, line 94
def satisfy_preconditions?
  errors.clear
  failed_preconditions.clear
  run_preconditions!
end

Private Instance Methods

run_preconditions!() click to toggle source
# File lib/granite/action/preconditions.rb, line 108
def run_preconditions!
  _preconditions.execute! self
  errors.empty?
end
run_validations!() click to toggle source
Calls superclass method
# File lib/granite/action/preconditions.rb, line 113
def run_validations!
  run_preconditions! && super
end