Method: ActiveInteractor::Interactor::Context::ClassMethods#contextualize_with

Defined in:
lib/active_interactor/interactor/context.rb

#contextualize_with(klass) ⇒ Const

Set the interactor class' context class

Examples:

class User < ActiveRecord::Base
end

class MyInteractor < ActiveInteractor::Base
  contextualize_with :user
end

MyInteractor.context_class
#=> User

Parameters:

  • klass (Const, Symbol, String)

    the class to use as context

Returns:

Raises:

Since:

  • 1.0.0



212
213
214
215
216
217
218
219
# File 'lib/active_interactor/interactor/context.rb', line 212

def contextualize_with(klass)
  @context_class = begin
    context_class = klass.to_s.camelize.safe_constantize
    raise(ActiveInteractor::Error::InvalidContextClass, klass) unless context_class

    context_class
  end
end