Module: ActiveInteraction::Runnable Abstract

Extended by:
ActiveSupport::Concern
Includes:
Transactable, ActiveModel::Validations
Included in:
Base
Defined in:
lib/active_interaction/concerns/runnable.rb

Overview

This module is abstract.

Include and override #execute to implement a custom Runnable class.

Note:

Must be included after ActiveModel::Validations.

Runs code in transactions and only provides the result if there are no

validation errors.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Transactable

#transaction

Instance Method Details

#errorsErrors

Returns:



23
24
25
# File 'lib/active_interaction/concerns/runnable.rb', line 23

def errors
  @_interaction_errors
end

#executeObject

This method is abstract.

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/active_interaction/concerns/runnable.rb', line 30

def execute
  fail NotImplementedError
end

#resultObject?

Returns:

  • (Object)

    If there are no validation errors.

  • (nil)

    If there are validation errors.



36
37
38
# File 'lib/active_interaction/concerns/runnable.rb', line 36

def result
  @_interaction_result
end

#result=(result) ⇒ Object?

Parameters:

  • result (Object)

Returns:

  • (Object)

    If there are no validation errors.

  • (nil)

    If there are validation errors.



43
44
45
46
47
48
49
50
51
# File 'lib/active_interaction/concerns/runnable.rb', line 43

def result=(result)
  if errors.empty?
    @_interaction_result = result
    @_interaction_valid = true
  else
    @_interaction_result = nil
    @_interaction_valid = false
  end
end

#valid?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/active_interaction/concerns/runnable.rb', line 54

def valid?(*)
  if instance_variable_defined?(:@_interaction_valid)
    return @_interaction_valid
  end

  super
end