Module: InteractorSupport::RequestObject

Extended by:
ActiveSupport::Concern
Defined in:
lib/interactor_support/request_object.rb

Overview

A base module for building validated, transformable, and optionally nested request objects.

It builds on top of ActiveModel::Model, adds coercion, default values, attribute transforms, key rewriting, and automatic context conversion (via #to_context). It integrates tightly with InteractorSupport::Configuration to control return behavior and key formatting.

Examples:

Basic usage

class CreateUserRequest
  include InteractorSupport::RequestObject

  attribute :name, transform: [:strip, :downcase]
  attribute :email
  attribute :metadata, default: {}
end

CreateUserRequest.new(name: " JOHN ", email: "[email protected]")
# => { name: "john", email: "[email protected]", metadata: {} }

Key rewriting

class UploadRequest
  include InteractorSupport::RequestObject

  attribute :image, rewrite: :image_url
end

UploadRequest.new(image: "url").image_url # => "url"

See Also:

Defined Under Namespace

Classes: TypeError

Constant Summary collapse

SUPPORTED_ACTIVEMODEL_TYPES =
ActiveModel::Type.registry.send(:registrations).keys.map { |type| ":#{type}" }
SUPPORTED_PRIMITIVES =
['AnyClass', 'Symbol', 'Hash', 'Array']
SUPPORTED_TYPES =
SUPPORTED_PRIMITIVES + SUPPORTED_ACTIVEMODEL_TYPES