Class: CMDx::AttributeValue
- Inherits:
-
Object
- Object
- CMDx::AttributeValue
- Extended by:
- Forwardable
- Defined in:
- lib/cmdx/attribute_value.rb
Overview
Manages the value lifecycle for a single attribute within a task. Handles value sourcing, derivation, coercion, and validation through a coordinated pipeline that ensures data integrity and type safety.
Instance Attribute Summary collapse
-
#attribute ⇒ Attribute
readonly
Returns the attribute managed by this value handler.
Instance Method Summary collapse
-
#generate ⇒ Object?
Generates the attribute value through the complete pipeline: sourcing, derivation, coercion, and storage.
-
#initialize(attribute) ⇒ AttributeValue
constructor
Creates a new attribute value manager for the given attribute.
-
#validate ⇒ Object
Validates the current attribute value against configured validators.
-
#value ⇒ Object?
Retrieves the current value for this attribute from the task’s attributes.
Constructor Details
#initialize(attribute) ⇒ AttributeValue
Creates a new attribute value manager for the given attribute.
33 34 35 |
# File 'lib/cmdx/attribute_value.rb', line 33 def initialize(attribute) @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Attribute (readonly)
Returns the attribute managed by this value handler.
19 20 21 |
# File 'lib/cmdx/attribute_value.rb', line 19 def attribute @attribute end |
Instance Method Details
#generate ⇒ Object?
Generates the attribute value through the complete pipeline: sourcing, derivation, coercion, and storage.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cmdx/attribute_value.rb', line 58 def generate return value if attributes.key?(method_name) sourced_value = source_value return if errors.for?(method_name) derived_value = derive_value(sourced_value) return if errors.for?(method_name) coerced_value = coerce_value(derived_value) transformed_value = transform_value(coerced_value) return if errors.for?(method_name) attributes[method_name] = transformed_value end |
#validate ⇒ Object
Validates the current attribute value against configured validators.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cmdx/attribute_value.rb', line 83 def validate registry = task.class.settings[:validators] .slice(*registry.keys).each do |type, opts| registry.validate(type, task, value, opts) rescue ValidationError => e errors.add(method_name, e.) nil end end |
#value ⇒ Object?
Retrieves the current value for this attribute from the task’s attributes.
45 46 47 |
# File 'lib/cmdx/attribute_value.rb', line 45 def value attributes[method_name] end |