Class: Yes::Core::Aggregate::Dsl::ConstantResolver Private

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/aggregate/dsl/constant_resolver.rb

Overview

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

Handles finding and setting constants based on conventional naming

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(class_name_convention) ⇒ ConstantResolver

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.

Returns a new instance of ConstantResolver.

Parameters:

Since:

  • 0.1.0



12
13
14
# File 'lib/yes/core/aggregate/dsl/constant_resolver.rb', line 12

def initialize(class_name_convention)
  @class_name_convention = class_name_convention
end

Instance Method Details

#find_conventional_class(type, name) ⇒ Class?

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.

Attempts to find a class based on conventional naming

Parameters:

  • type (Symbol)

    The type of class to find (:command, :event, or :handler)

  • name (Symbol)

    The name of the class

Returns:

  • (Class, nil)

    The found class or nil if not found

Since:

  • 0.1.0



21
22
23
24
25
26
# File 'lib/yes/core/aggregate/dsl/constant_resolver.rb', line 21

def find_conventional_class(type, name)
  class_name = class_name_convention.class_name_for(type, name)
  class_name.constantize
rescue NameError
  nil
end

#set_constant_for(type, name, klass) ⇒ Class

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.

Sets the generated class as a constant in the appropriate module path

Parameters:

  • type (Symbol)

    The type of class (:command, :event, or :handler, …)

  • name (Symbol)

    The name for the class

  • klass (Class)

    The class to set as constant

Returns:

  • (Class)

    The set class

Since:

  • 0.1.0



34
35
36
37
38
39
40
41
# File 'lib/yes/core/aggregate/dsl/constant_resolver.rb', line 34

def set_constant_for(type, name, klass)
  class_name = class_name_convention.class_name_for(type, name)
  modules = class_name.split('::')
  class_name = modules.pop

  parent_module = create_module_hierarchy(modules)
  parent_module.const_set(class_name, klass)
end