Module: InteractorSupport::Concerns::Transformable

Extended by:
ActiveSupport::Concern
Includes:
InteractorSupport::Core
Defined in:
lib/interactor_support/concerns/transformable.rb

Overview

Adds helpers for assigning and transforming values in interactor context.

The context_variable method sets static or dynamic values before the interactor runs. The transform method allows chaining transformations (methods or lambdas) on context values.

Examples:

Assign context variables before the interactor runs

context_variable user: -> { User.find(user_id) }, numbers: [1, 2, 3]

Normalize email and name before using them

transform :email, :name, with: [:strip, :downcase]

Apply a lambda to clean up input

transform :name, with: ->(value) { value.gsub(/\s+/, ' ').strip }

Mixing symbols and lambdas

transform :email, with: [:strip, :downcase, -> { email.gsub(/\s+/, '') }]

See Also:

Method Summary

Methods included from InteractorSupport::Core

included