Class: ApiBlocks::Interactor

Inherits:
Object
  • Object
show all
Includes:
Dry::Transaction
Defined in:
lib/api_blocks/interactor.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.input_schemaObject

Returns the value of attribute input_schema.



44
45
46
# File 'lib/api_blocks/interactor.rb', line 44

def input_schema
  @input_schema
end

Class Method Details

.call(*args) ⇒ Object

Call the interactor with its arguments.

Examples:


InviteUser.call(
  email: "[email protected]",
  first_name: "Foo",
  last_name: "Bar"
)


76
77
78
# File 'lib/api_blocks/interactor.rb', line 76

def self.call(*args)
  new.call(*args)
end

.input(&block) ⇒ Object

Define a contract for the input of this interactor using ‘dry-validation`

Examples:


class FooInteractor < ApiBlocks::Interactor
  input do
    schema do
      required(:bar).filled
    end
  end

  step :validate_input!
end


62
63
64
# File 'lib/api_blocks/interactor.rb', line 62

def self.input(&block)
  @input_schema = Class.new(Dry::Validation::Contract, &block).new
end

.with_step_args(*args) ⇒ Object

Call the interactor with additional step arguments.

Examples:


InviteUser.with_step_args(deliver_invitation: [mailer: UserMailer])


86
87
88
# File 'lib/api_blocks/interactor.rb', line 86

def self.with_step_args(*args)
  new.with_step_args(*args)
end