Module: ActiveInteractor::Context::Loader Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Find or create context classes for a given interactor

Author:

Since:

  • 1.0.0

Constant Summary collapse

BASE_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

ActiveInteractor base classes

Returns:

  • (Array<Const>)

Since:

  • 1.0.0

[ActiveInteractor::Base, ActiveInteractor::Organizer::Base].freeze
BASE_CONTEXT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The Base class

Returns:

  • (Const)

Since:

  • 1.0.0

ActiveInteractor::Context::Base

Class Method Summary collapse

Class Method Details

.create(context_class_name, interactor_class) ⇒ Const

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a context class for a given interactor

Parameters:

  • context_class_name (Symbol, String)

    the class name of the context class to create

  • interactor_class (Const)

    an interactor class

Returns:

  • (Const)

    a class that inherits from Base

Since:

  • 1.0.0



24
25
26
# File 'lib/active_interactor/context/loader.rb', line 24

def self.create(context_class_name, interactor_class)
  interactor_class.const_set(context_class_name.to_s.camelize, Class.new(BASE_CONTEXT))
end

.find_or_create(interactor_class) ⇒ Const

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find or create a context class for a given interactor. If a class exists following the pattern of InteractorNameContext or InteractorName::Context then that class will be returned otherwise a new class will be created with the pattern InteractorName::Context.

Parameters:

  • interactor_class (Const)

    an interactor class

Returns:

  • (Const)

    a class that inherits from Base

Since:

  • 1.0.0



34
35
36
37
38
39
# File 'lib/active_interactor/context/loader.rb', line 34

def self.find_or_create(interactor_class)
  return BASE_CONTEXT if BASE_CLASSES.include?(interactor_class)

  klass = possible_classes(interactor_class).first
  klass || create('Context', interactor_class)
end