Class: Treaty::Entity::Attribute::Option::Registry
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Option::Registry
- Defined in:
- lib/treaty/entity/attribute/option/registry.rb
Overview
Central registry for all option processors (validators, modifiers, and conditionals).
Purpose
Provides a centralized registry pattern for managing all option processors. Enables dynamic discovery and extensibility of the option system.
Responsibilities
- Registration - Stores option processor classes
- Retrieval - Provides access to registered processors
- Categorization - Organizes processors by category (validator/modifier/conditional)
- Validation - Checks if options are registered
Registered Options
Validators (sorted by position)
:type→ TypeValidator (position: 100):required→ RequiredValidator (position: 200):inclusion→ InclusionValidator (position: 300):format→ FormatValidator (position: 400)
Modifiers (sorted by position)
:transform→ TransformModifier (position: 500):cast→ CastModifier (position: 600):computed→ ComputedModifier (position: 700):default→ DefaultModifier (position: 800):as→ AsModifier (position: 900)
Conditionals (no position - handled separately)
:if→ IfConditional:unless→ UnlessConditional
Usage
Registration (done in RegistryInitializer):
Registry.register(:required, RequiredValidator, category: :validator, position: 200)
Registry.register(:if, IfConditional, category: :conditional)
Retrieval (done in OptionOrchestrator):
processor_class = Registry.processor_for(:required)
processor = processor_class.new(...)
Extensibility
To add a new option:
- Create processor class inheriting from Option::Base
- Register it:
Registry.register(:my_option, MyProcessor, category: :validator) - Option becomes available in DSL immediately
Architecture
Works with:
- RegistryInitializer - Populates registry with built-in options
- OptionOrchestrator - Uses registry to build processors
- Option::Base - Base class for all registered processors
Class Method Summary collapse
-
.all_options ⇒ Array<Symbol>
Get all registered option names.
-
.category_for(option_name) ⇒ Symbol?
Get category for an option.
-
.conditionals ⇒ Hash
Get all conditionals.
-
.modifiers ⇒ Hash
Get all modifiers.
-
.position_for(option_name) ⇒ Integer?
Get position for an option.
-
.processor_for(option_name) ⇒ Class?
Get processor class for an option.
-
.register(option_name, processor_class, category:, position: nil) ⇒ Object
Register an option processor.
-
.registered?(option_name) ⇒ Boolean
Check if an option is registered.
-
.reset! ⇒ Object
Reset registry (mainly for testing).
-
.validators ⇒ Hash
Get all validators.
Class Method Details
.all_options ⇒ Array<Symbol>
Get all registered option names
114 115 116 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 114 def registry.keys end |
.category_for(option_name) ⇒ Symbol?
Get category for an option
91 92 93 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 91 def category_for(option_name) registry.dig(option_name, :category) end |
.conditionals ⇒ Hash
Get all conditionals
137 138 139 140 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 137 def conditionals registry.select { |_, info| info.fetch(:category) == :conditional } .transform_values { |info| info.fetch(:processor_class) } end |
.modifiers ⇒ Hash
Get all modifiers
129 130 131 132 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 129 def modifiers registry.select { |_, info| info.fetch(:category) == :modifier } .transform_values { |info| info.fetch(:processor_class) } end |
.position_for(option_name) ⇒ Integer?
Get position for an option
99 100 101 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 99 def position_for(option_name) registry.dig(option_name, :position) end |
.processor_for(option_name) ⇒ Class?
Get processor class for an option
83 84 85 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 83 def processor_for(option_name) registry.dig(option_name, :processor_class) end |
.register(option_name, processor_class, category:, position: nil) ⇒ Object
Register an option processor
71 72 73 74 75 76 77 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 71 def register(option_name, processor_class, category:, position: nil) registry[option_name] = { processor_class:, category:, position: } end |
.registered?(option_name) ⇒ Boolean
Check if an option is registered
107 108 109 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 107 def registered?(option_name) registry.key?(option_name) end |
.reset! ⇒ Object
Reset registry (mainly for testing)
143 144 145 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 143 def reset! @registry = nil end |
.validators ⇒ Hash
Get all validators
121 122 123 124 |
# File 'lib/treaty/entity/attribute/option/registry.rb', line 121 def validators registry.select { |_, info| info.fetch(:category) == :validator } .transform_values { |info| info.fetch(:processor_class) } end |