Class: Pangea::Resources::ResourceReference
- Defined in:
- lib/pangea/resources/reference.rb
Overview
Resource reference object returned by resource functions Provides access to resource attributes, outputs, and computed properties
Constant Summary collapse
- @@computed_attributes_registry =
Registry for provider-specific computed attributes classes
{}
Class Method Summary collapse
-
.register_computed_attributes(mapping) ⇒ Object
Register computed attributes classes for resource types.
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Object
Alias for ref - more natural syntax.
- #arn ⇒ Object
-
#computed_attributes ⇒ Object
Resource-specific computed properties (extensible via register_computed_attributes).
-
#id ⇒ Object
Access to common outputs with friendly names.
-
#method_missing(method_name, *args, &block) ⇒ Object
Method delegation to outputs, computed properties, computed attributes, and finally a catch-all that generates a Terraform attribute reference.
-
#ref(attribute_name) ⇒ Object
Generate terraform reference for any attribute.
-
#resource_type ⇒ Object
Alias for ‘type` — some callers prefer `resource_type` to avoid conflicts.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#to_h ⇒ Object
Convert to hash for terraform-synthesizer integration.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Method delegation to outputs, computed properties, computed attributes, and finally a catch-all that generates a Terraform attribute reference.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/pangea/resources/reference.rb', line 107 def method_missing(method_name, *args, &block) if outputs.key?(method_name) outputs[method_name] elsif computed_properties&.key?(method_name) computed_properties[method_name] elsif computed&.key?(method_name) computed[method_name] elsif computed_attributes.respond_to?(method_name) computed_attributes.public_send(method_name, *args, &block) elsif method_name.to_s.match?(/\A[a-z_][a-z0-9_]*\z/) && args.empty? ref(method_name) else super end end |
Class Method Details
.register_computed_attributes(mapping) ⇒ Object
Register computed attributes classes for resource types
69 70 71 |
# File 'lib/pangea/resources/reference.rb', line 69 def self.register_computed_attributes(mapping) @@computed_attributes_registry.merge!(mapping) end |
Instance Method Details
#[](attribute_name) ⇒ Object
Alias for ref - more natural syntax
84 85 86 |
# File 'lib/pangea/resources/reference.rb', line 84 def [](attribute_name) ref(attribute_name) end |
#arn ⇒ Object
93 94 95 |
# File 'lib/pangea/resources/reference.rb', line 93 def arn ref(:arn) end |
#computed_attributes ⇒ Object
Resource-specific computed properties (extensible via register_computed_attributes)
98 99 100 101 102 103 |
# File 'lib/pangea/resources/reference.rb', line 98 def computed_attributes @computed_attributes ||= begin klass = @@computed_attributes_registry[type] klass ? klass.new(self) : BaseComputedAttributes.new(self) end end |
#id ⇒ Object
Access to common outputs with friendly names
89 90 91 |
# File 'lib/pangea/resources/reference.rb', line 89 def id ref(:id) end |
#ref(attribute_name) ⇒ Object
Generate terraform reference for any attribute
79 80 81 |
# File 'lib/pangea/resources/reference.rb', line 79 def ref(attribute_name) ReferenceGenerator::RESOURCE_REF.call(type, name, attribute_name) end |
#resource_type ⇒ Object
Alias for ‘type` — some callers prefer `resource_type` to avoid conflicts
74 75 76 |
# File 'lib/pangea/resources/reference.rb', line 74 def resource_type type.to_sym end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
123 124 125 126 127 128 129 130 |
# File 'lib/pangea/resources/reference.rb', line 123 def respond_to_missing?(method_name, include_private = false) outputs.key?(method_name) || computed_properties&.key?(method_name) || computed&.key?(method_name) || computed_attributes.respond_to?(method_name, include_private) || method_name.to_s.match?(/\A[a-z_][a-z0-9_]*\z/) || super end |
#to_h ⇒ Object
Convert to hash for terraform-synthesizer integration
133 134 135 136 137 138 139 140 |
# File 'lib/pangea/resources/reference.rb', line 133 def to_h @_to_h ||= { type: type, name: name, attributes: resource_attributes, # Use 'attributes' as key for compatibility outputs: outputs }.freeze end |