class Puppet::Type::RelationshipMetaparam
RelationshipMetaparam is an implementation supporting the meta-parameters `:require`, `:subscribe`, `:notify`, and `:before`.
Attributes
Public Class Methods
# File lib/puppet/type.rb 1470 def self.inherited(sub) 1471 @subclasses << sub 1472 end
Public Instance Methods
@return [Array<Puppet::Resource>] turns attribute values into list of resources
# File lib/puppet/type.rb 1475 def munge(references) 1476 references = [references] unless references.is_a?(Array) 1477 references.collect do |ref| 1478 if ref.is_a?(Puppet::Resource) 1479 ref 1480 else 1481 Puppet::Resource.new(ref) 1482 end 1483 end 1484 end
Creates edges for all relationships. The `:in` relationships are specified by the event-receivers, and `:out` relationships are specified by the event generator. @todo references to “event-receivers” and “event generator” means in this context - are those just
the resources at the two ends of the relationship?
This way 'source' and 'target' are consistent terms in both edges and events, i.e. an event targets edges whose source matches the event's source. The direction of the relationship determines which resource is applied first and which resource is considered to be the event generator. @return [Array<Puppet::Relationship>] @raise [???fail] when a reference can not be resolved
# File lib/puppet/type.rb 1513 def to_edges 1514 @value.collect do |reference| 1515 reference.catalog = resource.catalog 1516 1517 # Either of the two retrieval attempts could have returned 1518 # nil. 1519 related_resource = reference.resolve 1520 unless related_resource 1521 self.fail "Could not retrieve dependency '#{reference}' of #{@resource.ref}" 1522 end 1523 1524 # Are we requiring them, or vice versa? See the method docs 1525 # for further info on this. 1526 if self.class.direction == :in 1527 source = related_resource 1528 target = @resource 1529 else 1530 source = @resource 1531 target = related_resource 1532 end 1533 1534 method = self.class.callback 1535 if method 1536 subargs = { 1537 :event => self.class.events, 1538 :callback => method 1539 } 1540 else 1541 # If there's no callback, there's no point in even adding 1542 # a label. 1543 subargs = nil 1544 end 1545 1546 ## Corrected syntax of debug statement to reflect the way this was called. 1547 # i.e. before, after, subscribe, notify 1548 self.debug do 1549 relation = case self.class.name 1550 when "subscribe" 1551 "subscribes" 1552 when "notify" 1553 "notifies" 1554 else 1555 self.class.name 1556 end 1557 1558 "#{relation} to #{related_resource.ref}" 1559 end 1560 1561 Puppet::Relationship.new(source, target, subargs) 1562 end 1563 end
Checks each reference to assert that what it references exists in the catalog.
@raise [???fail] if the referenced resource can not be found @return [void]
# File lib/puppet/type.rb 1490 def validate_relationship 1491 @value.each do |ref| 1492 unless @resource.catalog.resource(ref.to_s) 1493 description = self.class.direction == :in ? "dependency" : "dependent" 1494 fail ResourceError, _("Could not find %{description} %{ref} for %{resource}") % 1495 { description: description, ref: ref, resource: resource.ref } 1496 end 1497 end 1498 end