Sha256: a0714e67537ef8b2316c05d5fbda87f7593b3851c032549d3e43ccbf11a7e071

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

require 'puppet'
require 'puppet/type'
require 'puppet/transaction'

Puppet::Type.newtype(:component) do
  include Enumerable

  newparam(:name) do
    desc "The name of the component.  Generally optional."
    isnamevar
  end

  # Override how parameters are handled so that we support the extra
  # parameters that are used with defined resource types.
  def [](param)
    return super if self.class.valid_parameter?(param)
    @extra_parameters[param.to_sym]
  end

  # Override how parameters are handled so that we support the extra
  # parameters that are used with defined resource types.
  def []=(param, value)
    return super if self.class.valid_parameter?(param)
    @extra_parameters[param.to_sym] = value
  end

  # Initialize a new component
  def initialize(*args)
    @extra_parameters = {}
    super
  end

  # Component paths are special because they function as containers.
  def pathbuilder
    if reference.type == "Class"
      # 'main' is the top class, so we want to see '//' instead of
      # its name.
      if reference.title.to_s.downcase == "main"
        myname = ""
      else
        myname = reference.title
      end
    else
      myname = reference.to_s
    end
    if p = self.parent
      return [p.pathbuilder, myname]
    else
      return [myname]
    end
  end

  def ref
    reference.to_s
  end

  # We want our title to just be the whole reference, rather than @title.
  def title
    ref
  end

  def title=(str)
    @reference = Puppet::Resource.new(str)
  end

  def refresh
    catalog.adjacent(self).each do |child|
      if child.respond_to?(:refresh)
        child.refresh
        child.log "triggering #{:refresh}"
      end
    end
  end

  def to_s
    reference.to_s
  end

  private

  attr_reader :reference
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-3.3.2 lib/puppet/type/component.rb
puppet-3.3.1 lib/puppet/type/component.rb
puppet-3.3.1.rc3 lib/puppet/type/component.rb
puppet-3.3.1.rc2 lib/puppet/type/component.rb
puppet-3.3.1.rc1 lib/puppet/type/component.rb
puppet-3.3.0 lib/puppet/type/component.rb
puppet-3.3.0.rc3 lib/puppet/type/component.rb
puppet-3.3.0.rc2 lib/puppet/type/component.rb