Module: ActiveInteractor::Models

Defined in:
lib/active_interactor/models.rb

Overview

Helper methods for using classes that do not inherit from Context::Base as context objects for interactors. Classes should extend Models.

Author:

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#acts_as_contextObject

Note:

You must include ActiveModel::Model and ActiveModel::Attributes or a similar implementation for the object to function properly.

Include methods needed for a context class to function properly.

Examples:

class User
  include ActiveModel::Model
  include ActiveModel::Attributes
  extend ActiveInteractor::Models
  acts_as_context
end

class MyInteractor < ActiveInteractor::Base
  contextualize_with :user
end

Since:

  • 1.0.0



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_interactor/models.rb', line 38

def acts_as_context
  class_eval do
    extend ActiveInteractor::Context::Attributes::ClassMethods

    include ActiveInteractor::Context::Attributes
    include ActiveInteractor::Context::Errors
    include ActiveInteractor::Context::Status
    include ActiveInteractor::Models::InstanceMethods
    delegate :each_pair, to: :attributes
  end
end