Method: Puppet::MetaType::Manager#type

Defined in:
lib/puppet/metatype/manager.rb

#type(name) ⇒ Puppet::Type?

Returns a Type instance by name. This will load the type if not already defined.

Parameters:

  • name (String, Symbol)

    of the wanted Type

Returns:

  • (Puppet::Type, nil)

    the type or nil if the type was not defined and could not be loaded



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/puppet/metatype/manager.rb', line 155

def type(name)
  @manager_lock.synchronize do
    # Avoid loading if name obviously is not a type name
    if name.to_s.include?(':')
      return nil
    end

    # We are overwhelmingly symbols here, which usually match, so it is worth
    # having this special-case to return quickly.  Like, 25K symbols vs. 300
    # strings in this method. --daniel 2012-07-17
    return @types[name] if @types.include? name

    # Try mangling the name, if it is a string.
    if name.is_a? String
      name = name.downcase.intern
      return @types[name] if @types.include? name
    end
    # Try loading the type.
    if typeloader.load(name, Puppet.lookup(:current_environment))
      # TRANSLATORS 'puppet/type/%{name}' should not be translated
      Puppet.warning(_("Loaded puppet/type/%{name} but no class was created") % { name: name }) unless @types.include? name
    elsif !Puppet[:always_retry_plugins]
      # PUP-5482 - Only look for a type once if plugin retry is disabled
      @types[name] = nil
    end

    # ...and I guess that is that, eh.
    return @types[name]
  end
end