Module: Interactor::ClassMethods

Defined in:
lib/interactor.rb

Overview

Internal: Interactor class methods.

Instance Method Summary collapse

Instance Method Details

#call(context = {}) ⇒ Object

Public: Invoke an Interactor. This is the primary public API method to an interactor.

context - A Hash whose key/value pairs are used in initializing a new

Interactor::Context object. An existing Interactor::Context may
also be given. (default: {})

Examples

MyInteractor.call(foo: "bar")
# => #<Interactor::Context foo="bar">

MyInteractor.call
# => #<Interactor::Context>

Returns the resulting Interactor::Context after manipulation by the

interactor.


49
50
51
# File 'lib/interactor.rb', line 49

def call(context = {})
  new(context).tap(&:run).context
end

#call!(context = {}) ⇒ Object

Public: Invoke an Interactor. The “call!” method behaves identically to the “call” method with one notable exception. If the context is failed during invocation of the interactor, the Interactor::Failure is raised.

context - A Hash whose key/value pairs are used in initializing a new

Interactor::Context object. An existing Interactor::Context may
also be given. (default: {})

Examples

MyInteractor.call!(foo: "bar")
# => #<Interactor::Context foo="bar">

MyInteractor.call!
# => #<Interactor::Context>

MyInteractor.call!(foo: "baz")
# => Interactor::Failure: #<Interactor::Context foo="baz">

Returns the resulting Interactor::Context after manipulation by the

interactor.

Raises Interactor::Failure if the context is failed.



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

def call!(context = {})
  new(context).tap(&:run!).context
end