Class: CMDx::AttributeRegistry
- Inherits:
-
Object
- Object
- CMDx::AttributeRegistry
- Defined in:
- lib/cmdx/attribute_registry.rb
Overview
Manages a collection of attributes for task definition and verification. The registry provides methods to register, deregister, and process attributes in a hierarchical structure, supporting nested attribute definitions.
Instance Attribute Summary collapse
-
#registry ⇒ Array<Attribute>
(also: #to_a)
readonly
Returns the collection of registered attributes.
Instance Method Summary collapse
-
#define_and_verify(task) ⇒ Object
Associates all registered attributes with a task and verifies their definitions.
-
#deregister(names) ⇒ AttributeRegistry
Removes attributes from the registry by name.
-
#dup ⇒ AttributeRegistry
Creates a duplicate of this registry with copied attributes.
-
#initialize(registry = []) ⇒ AttributeRegistry
constructor
Creates a new attribute registry with an optional initial collection.
-
#register(attributes) ⇒ AttributeRegistry
Registers one or more attributes to the registry.
Constructor Details
#initialize(registry = []) ⇒ AttributeRegistry
Creates a new attribute registry with an optional initial collection.
31 32 33 |
# File 'lib/cmdx/attribute_registry.rb', line 31 def initialize(registry = []) @registry = registry end |
Instance Attribute Details
#registry ⇒ Array<Attribute> (readonly) Also known as: to_a
Returns the collection of registered attributes.
17 18 19 |
# File 'lib/cmdx/attribute_registry.rb', line 17 def registry @registry end |
Instance Method Details
#define_and_verify(task) ⇒ Object
Associates all registered attributes with a task and verifies their definitions. This method is called during task setup to establish attribute-task relationships and validate the attribute hierarchy.
90 91 92 93 94 95 |
# File 'lib/cmdx/attribute_registry.rb', line 90 def define_and_verify(task) registry.each do |attribute| attribute.task = task attribute.define_and_verify_tree end end |
#deregister(names) ⇒ AttributeRegistry
Removes attributes from the registry by name. Supports hierarchical attribute removal by matching the entire attribute tree.
75 76 77 78 79 80 81 |
# File 'lib/cmdx/attribute_registry.rb', line 75 def deregister(names) Array(names).each do |name| @registry.reject! { |attribute| matches_attribute_tree?(attribute, name.to_sym) } end self end |
#dup ⇒ AttributeRegistry
Creates a duplicate of this registry with copied attributes.
43 44 45 |
# File 'lib/cmdx/attribute_registry.rb', line 43 def dup self.class.new(registry.dup) end |
#register(attributes) ⇒ AttributeRegistry
Registers one or more attributes to the registry.
58 59 60 61 |
# File 'lib/cmdx/attribute_registry.rb', line 58 def register(attributes) @registry.concat(Array(attributes)) self end |