Method: Puppet::Type#initialize
- Defined in:
- lib/puppet/type.rb
#initialize(hash) ⇒ Type #initialize(resource) ⇒ Type
TODO:
Unclear if this is a new Type or a new instance of a given type (the initialization ends with calling validate - which seems like validation of an instance of a given type, not a new meta type.
TODO:
Explain what the Hash and Resource are. There seems to be two different types of resources; one that causes the title to be set to resource.title, and one that causes the title to be resource.ref (“for components”) - what is a component?
Creates an instance of Type from a hash or a Resource.
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 |
# File 'lib/puppet/type.rb', line 2315 def initialize(resource) resource = self.class.hash2resource(resource) unless resource.is_a?(Puppet::Resource) # The list of parameter/property instances. @parameters = {} # Set the title first, so any failures print correctly. if resource.type.to_s.downcase.to_sym == self.class.name self.title = resource.title else # This should only ever happen for components self.title = resource.ref end [:file, :line, :catalog, :exported, :virtual].each do |getter| setter = getter.to_s + "=" val = resource.send(getter) send(setter, val) if val end (resource) @original_parameters = resource.to_hash set_name(@original_parameters) set_default(:provider) set_parameters(@original_parameters) validate_resource set_sensitive_parameters(resource.sensitive_parameters) end |