Class: Puppet::Type::RelationshipMetaparam

Inherits:
Parameter show all
Defined in:
lib/puppet/type.rb

Class Attribute Summary collapse

Attributes inherited from Parameter

#parent, #resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parameter

aliasvalue, defaultto, desc, #devfail, doc, #fail, format_value_for_display, #initialize, initvars, isnamevar, isnamevar?, isrequired, #log, #metaparam?, munge, #name, newvalues, nodefault, #noop, #pathbuilder, #provider, proxymethods, #remove, required?, #tags, #to_s, unmunge, #unmunge, #unsafe_munge, #unsafe_validate, validate, #validate, #value, #value=

Methods included from Util::Docs

#desc, #dochook, #doctable, #nodoc?, #pad, scrub

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #send_log

Methods included from Util::LogPaths

#path, #source_descriptors

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

This class inherits a constructor from Puppet::Parameter

Class Attribute Details

.callbackObject

Returns the value of attribute callback.



1151
1152
1153
# File 'lib/puppet/type.rb', line 1151

def callback
  @callback
end

.directionObject

Returns the value of attribute direction.



1151
1152
1153
# File 'lib/puppet/type.rb', line 1151

def direction
  @direction
end

.eventsObject

Returns the value of attribute events.



1151
1152
1153
# File 'lib/puppet/type.rb', line 1151

def events
  @events
end

.subclassesObject

Returns the value of attribute subclasses.



1151
1152
1153
# File 'lib/puppet/type.rb', line 1151

def subclasses
  @subclasses
end

Class Method Details

.inherited(sub) ⇒ Object



1156
1157
1158
# File 'lib/puppet/type.rb', line 1156

def self.inherited(sub)
  @subclasses << sub
end

Instance Method Details

#munge(references) ⇒ Object



1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
# File 'lib/puppet/type.rb', line 1160

def munge(references)
  references = [references] unless references.is_a?(Array)
  references.collect do |ref|
    if ref.is_a?(Puppet::Resource)
      ref
    else
      Puppet::Resource.new(ref)
    end
  end
end

#to_edgesObject

Create edges from each of our relationships. :in relationships are specified by the event-receivers, and :out relationships are specified by the event generator. This way ‘source’ and ‘target’ are consistent terms in both edges and events – that is, 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.



1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'lib/puppet/type.rb', line 1188

def to_edges
  @value.collect do |reference|
    reference.catalog = resource.catalog

    # Either of the two retrieval attempts could have returned
    # nil.
    unless related_resource = reference.resolve
      self.fail "Could not retrieve dependency '#{reference}' of #{@resource.ref}"
    end

    # Are we requiring them, or vice versa?  See the method docs
    # for futher info on this.
    if self.class.direction == :in
      source = related_resource
      target = @resource
    else
      source = @resource
      target = related_resource
    end

    if method = self.class.callback
      subargs = {
        :event => self.class.events,
        :callback => method
      }
      self.debug("subscribes to #{related_resource.ref}")
    else
      # If there's no callback, there's no point in even adding
      # a label.
      subargs = nil
      self.debug("requires #{related_resource.ref}")
    end

    rel = Puppet::Relationship.new(source, target, subargs)
  end
end

#validate_relationshipObject



1171
1172
1173
1174
1175
1176
1177
1178
# File 'lib/puppet/type.rb', line 1171

def validate_relationship
  @value.each do |ref|
    unless @resource.catalog.resource(ref.to_s)
      description = self.class.direction == :in ? "dependency" : "dependent"
      fail "Could not find #{description} #{ref} for #{resource.ref}"
    end
  end
end