Class: Puppet::Parser::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/parser/relationship.rb

Constant Summary collapse

PARAM_MAP =
{:relationship => :before, :subscription => :notify}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, type) ⇒ Relationship

Returns a new instance of Relationship.



24
25
26
# File 'lib/puppet/parser/relationship.rb', line 24

def initialize(source, target, type)
  @source, @target, @type = source, target, type
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



2
3
4
# File 'lib/puppet/parser/relationship.rb', line 2

def source
  @source
end

#targetObject

Returns the value of attribute target.



2
3
4
# File 'lib/puppet/parser/relationship.rb', line 2

def target
  @target
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/puppet/parser/relationship.rb', line 2

def type
  @type
end

Instance Method Details

#evaluate(catalog) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/parser/relationship.rb', line 6

def evaluate(catalog)
  if source.is_a?(Puppet::Parser::Collector)
    sources = source.collected.values
  else
    sources = [source]
  end
  if target.is_a?(Puppet::Parser::Collector)
    targets = target.collected.values
  else
    targets = [target]
  end
  sources.each do |s|
    targets.each do |t|
      mk_relationship(s, t, catalog)
    end
  end
end

#mk_relationship(source, target, catalog) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/puppet/parser/relationship.rb', line 32

def mk_relationship(source, target, catalog)
  unless source_resource = catalog.resource(source.to_s)
    raise ArgumentError, "Could not find resource '#{source}' for relationship on '#{target}'"
  end
  unless target_resource = catalog.resource(target.to_s)
    raise ArgumentError, "Could not find resource '#{target}' for relationship from '#{source}'"
  end
  Puppet.debug "Adding relationship from #{source.to_s} to #{target.to_s} with '#{param_name}'"
  source_resource[param_name] ||= []
  source_resource[param_name] << target.to_s
end

#param_nameObject



28
29
30
# File 'lib/puppet/parser/relationship.rb', line 28

def param_name
  PARAM_MAP[type] || raise(ArgumentError, "Invalid relationship type #{type}")
end