module ActiveInteraction::Runnable
@abstract Include and override {#execute} to implement a custom Runnable
class.
@note Must be included after `ActiveModel::Validations`.
Runs code and provides the result.
@private
Public Instance Methods
errors()
click to toggle source
@return [Errors]
# File lib/active_interaction/concerns/runnable.rb, line 21 def errors @_interaction_errors end
execute()
click to toggle source
@abstract
@raise [NotImplementedError]
# File lib/active_interaction/concerns/runnable.rb, line 28 def execute raise NotImplementedError end
result()
click to toggle source
@return [Object] If there are no validation errors. @return [nil] If there are validation errors.
# File lib/active_interaction/concerns/runnable.rb, line 34 def result @_interaction_result end
result=(result)
click to toggle source
@param result [Object]
@return (see result
)
# File lib/active_interaction/concerns/runnable.rb, line 41 def result=(result) @_interaction_result = result @_interaction_valid = errors.empty? end
valid?(*)
click to toggle source
@return [Boolean]
Calls superclass method
# File lib/active_interaction/concerns/runnable.rb, line 47 def valid?(*) return @_interaction_valid if instance_variable_defined?(:@_interaction_valid) super end
Private Instance Methods
compose(other, *args)
click to toggle source
@param other [Class] The other interaction. @param (see ClassMethods.run
)
@return (see result
)
@raise [Interrupt]
# File lib/active_interaction/concerns/runnable.rb, line 61 def compose(other, *args) outcome = other.run(*args) raise Interrupt, outcome.errors if outcome.invalid? outcome.result end
run()
click to toggle source
@return (see result=
) @return [nil]
# File lib/active_interaction/concerns/runnable.rb, line 71 def run return self.result = nil unless valid? self.result = run_callbacks(:execute) do execute rescue Interrupt => e errors.backtrace = e.errors.backtrace || e.backtrace errors.merge!(e.errors) end end
run!()
click to toggle source
@return [Object]
@raise [InvalidInteractionError] If there are validation errors.
# File lib/active_interaction/concerns/runnable.rb, line 85 def run! run return result if valid? e = InvalidInteractionError.new(errors.full_messages.join(', ')) e.interaction = self e.set_backtrace(errors.backtrace) if errors.backtrace raise e end