Method: Puppet::Type#newattr
- Defined in:
- lib/puppet/type.rb
#newattr(name) ⇒ Object #newattr(klass) ⇒ Object
Registers an attribute to this resource type instance. Requires either the attribute name or class as its argument. This is a noop if the named property/parameter is not supported by this resource. Otherwise, an attribute instance is created and kept in this resource’s parameters hash.
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'lib/puppet/type.rb', line 777 def newattr(name) if name.is_a?(Class) klass = name name = klass.name end klass = self.class.attrclass(name) unless klass raise Puppet::Error, "Resource type #{self.class.name} does not support parameter #{name}" end if provider and !provider.class.supports_parameter?(klass) missing = klass.required_features.find_all { |f| !provider.class.feature?(f) } debug "Provider %s does not support features %s; not managing attribute %s" % [provider.class.name, missing.join(", "), name] return nil end return @parameters[name] if @parameters.include?(name) @parameters[name] = klass.new(:resource => self) end |