Method: Onceover::Controlrepo#fixtures

Defined in:
lib/onceover/controlrepo.rb

#fixturesObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/onceover/controlrepo.rb', line 343

def fixtures
  # Load up the Puppetfile using R10k
  puppetfile = R10K::Puppetfile.new(@root)
  fail 'Could not load Puppetfile' unless puppetfile.load

  modules = puppetfile.modules

  # Iterate over everything and seperate it out for the sake of readability
  symlinks      = []
  forge_modules = []
  repositories  = []

  modules.each do |mod|
    logger.debug "Converting #{mod.to_s} to .fixtures.yml format"
    # This logic could probably be cleaned up. A lot.
    if mod.is_a? R10K::Module::Forge
      if mod.expected_version.is_a?(Hash)
        # Set it up as a symlink, because we are using local files in the Puppetfile
        symlinks << {
          'name' => mod.name,
          'dir'  => mod.expected_version[:path]
        }
      elsif mod.expected_version.is_a?(String)
        # Set it up as a normal forge module
        forge_modules << {
          'name' => mod.name,
          'repo' => mod.title,
          'ref'  => mod.expected_version
        }
      end
    elsif mod.is_a? R10K::Module::Git
      # Set it up as a git repo
      repositories << {
          'name' => mod.name,
          # I know I shouldn't be doing this, but trust me, there are no methods
          # anywhere that expose this value, I looked.
          'repo' => mod.instance_variable_get(:@remote),
          'ref'  => mod.version
        }
    end
  end

  # also add synlinks for anything that is in environment.conf
  code_dirs = self.config['modulepath']
  code_dirs.delete_if { |dir| dir[0] == '$'}
  code_dirs.each do |dir|
    # We need to traverse down into these directories and create a symlink for each
    # module we find because fixtures.yml is expecting the module's root not the
    # root of modulepath
    Dir["#{dir}/*"].each do |mod|
      symlinks << {
        'name' => File.basename(mod),
        'dir'  => Pathname.new(File.expand_path(mod)).relative_path_from(Pathname.new(@root))#File.expand_path(mod)
      }
    end
  end

  # Use an ERB template to write the files
  Onceover::Controlrepo.evaluate_template('.fixtures.yml.erb', binding)
end