Class: Yes::Core::Aggregate::Dsl::ConstantResolver Private
- Inherits:
-
Object
- Object
- Yes::Core::Aggregate::Dsl::ConstantResolver
- 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
Instance Method Summary collapse
-
#find_conventional_class(type, name) ⇒ Class?
private
Attempts to find a class based on conventional naming.
-
#initialize(class_name_convention) ⇒ ConstantResolver
constructor
private
A new instance of ConstantResolver.
-
#set_constant_for(type, name, klass) ⇒ Class
private
Sets the generated class as a constant in the appropriate module path.
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.
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
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
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 |