# File lib/puppet/resource/catalog.rb, line 222
222:     def extract_to_transportable
223:         top = nil
224:         current = nil
225:         buckets = {}
226: 
227:         unless main = vertices.find { |res| res.type == "Class" and res.title == :main }
228:             raise Puppet::DevError, "Could not find 'main' class; cannot generate catalog"
229:         end
230: 
231:         # Create a proc for examining edges, which we'll use to build our tree
232:         # of TransBuckets and TransObjects.
233:         bucket = nil
234:         walk(main, :out) do |source, target|
235:             # The sources are always non-builtins.
236:             unless tmp = buckets[source.to_s]
237:                 if tmp = buckets[source.to_s] = source.to_trans
238:                     bucket = tmp
239:                 else
240:                     # This is because virtual resources return nil.  If a virtual
241:                     # container resource contains realized resources, we still need to get
242:                     # to them.  So, we keep a reference to the last valid bucket
243:                     # we returned and use that if the container resource is virtual.
244:                 end
245:             end
246:             bucket = tmp || bucket
247:             if child = target.to_trans
248:                 unless bucket
249:                     raise "No bucket created for %s" % source
250:                 end
251:                 bucket.push child
252: 
253:                 # It's important that we keep a reference to any TransBuckets we've created, so
254:                 # we don't create multiple buckets for children.
255:                 unless target.builtin?
256:                     buckets[target.to_s] = child
257:                 end
258:             end
259:         end
260: 
261:         # Retrieve the bucket for the top-level scope and set the appropriate metadata.
262:         unless result = buckets[main.to_s]
263:             # This only happens when the catalog is entirely empty.
264:             result = buckets[main.to_s] = main.to_trans
265:         end
266: 
267:         result.classes = classes
268: 
269:         # Clear the cache to encourage the GC
270:         buckets.clear
271:         return result
272:     end