Module: ActiveInteractor::Interactor::Context::ClassMethods

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

Overview

Interactor context class methods. Because ClassMethods is a module classes should extend ClassMethods rather than inherit from it.

Author:

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#context_attribute(name, type = Type::Value.new, **options) ⇒ Object

Call .attribute on the interactor class' context class

Since:

  • 1.0.1



66
# File 'lib/active_interactor/interactor/context.rb', line 66

delegate(*ActiveModel::Attributes::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_attribute_method?(attribute) ⇒ Object

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_attribute_missing(match, *args, &block) ⇒ Object

Since:

  • 1.0.1



42
# File 'lib/active_interactor/interactor/context.rb', line 42

delegate :attributes, :attribute_missing, :respond_to_without_attributes?, to: :context_class, prefix: :context

#context_attribute_namesObject

Since:

  • 1.0.1



66
# File 'lib/active_interactor/interactor/context.rb', line 66

delegate(*ActiveModel::Attributes::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_attributes(*attributes) ⇒ Object

Call .attributes on the interactor class' context class

Examples:

class MyInteractor < ActiveInteractor::Base
  context_attributes :first_name, :last_name
end

MyInteractor.context_class.attributes
#=> [:first_name, :last_name]

Since:

  • 0.1.0



42
# File 'lib/active_interactor/interactor/context.rb', line 42

delegate :attributes, :attribute_missing, :respond_to_without_attributes?, to: :context_class, prefix: :context

#context_classConst

Get the interactor class' context class. If no class is found or no class is set via the #contextualize_with method a new class is created.

Returns:

See Also:

Since:

  • 0.1.0



190
191
192
# File 'lib/active_interactor/interactor/context.rb', line 190

def context_class
  @context_class ||= ActiveInteractor::Context::Loader.find_or_create(self)
end

#context_clear_validators!(attribute) ⇒ Object

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_respond_to_without_attributes?(method, include_private_methods = false) ⇒ Object

Since:

  • 1.0.1



42
# File 'lib/active_interactor/interactor/context.rb', line 42

delegate :attributes, :attribute_missing, :respond_to_without_attributes?, to: :context_class, prefix: :context

#context_validate(*args, &block) ⇒ Object

Call .validate on the interactor class' context class

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates(*attributes) ⇒ Object

Call .validates on the interactor class' context class

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates!(*attributes) ⇒ Object

Call .validates! on the interactor class' context class

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_absence_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_acceptance_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_confirmation_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_each(*attr_names, &block) ⇒ Object

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_exclusion_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_format_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_inclusion_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_length_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_numericality_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_presence_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_size_of(*attr_names) ⇒ Object

Since:

  • 0.1.0



182
# File 'lib/active_interactor/interactor/context.rb', line 182

delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :context_class, prefix: :context)

#context_validates_with(*args, &block) ⇒ Object

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validatorsObject

Call .validators on the interactor class' context class

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#context_validators_on(*attributes) ⇒ Object

Since:

  • 0.1.0



121
# File 'lib/active_interactor/interactor/context.rb', line 121

delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :context_class, prefix: :context)

#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