Class: Tdc::DefinitionResolvers::TagResolver
- Inherits:
-
DefinitionResolver
- Object
- DefinitionResolver
- Tdc::DefinitionResolvers::TagResolver
- Defined in:
- lib/tdc/definition_resolvers/tag_resolver.rb
Overview
Knows how to resolve the tag value for the specified instance_definition key by replacing it with an object sourced from the current catalog.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes inherited from DefinitionResolver
Instance Method Summary collapse
-
#initialize(key:, source:) ⇒ TagResolver
constructor
A new instance of TagResolver.
- #resolve(instance_definition) ⇒ Object
Methods inherited from DefinitionResolver
Constructor Details
#initialize(key:, source:) ⇒ TagResolver
Returns a new instance of TagResolver.
10 11 12 13 |
# File 'lib/tdc/definition_resolvers/tag_resolver.rb', line 10 def initialize(key:, source:) @key = key @source = source end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/tdc/definition_resolvers/tag_resolver.rb', line 8 def key @key end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/tdc/definition_resolvers/tag_resolver.rb', line 8 def source @source end |
Instance Method Details
#resolve(instance_definition) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tdc/definition_resolvers/tag_resolver.rb', line 15 def resolve(instance_definition) return unless instance_definition.key?(key) # Lookup the source catalog entry in the current_catalog. catalog_entry = instance_eval("current_catalog.#{source}", __FILE__, __LINE__) # Before resolution the instance definition value is a tag. tag = instance_definition[key] unresolvable_tag(tag, catalog_entry) unless tag # Use the tag to source an object from the current catalog. sourced_object = catalog_entry.send(tag) unresolvable_tag(tag, catalog_entry) unless sourced_object # Replace the tag value with the sourced object. instance_definition[key] = sourced_object end |