Module: PuppetfileFixturesGenerator

Defined in:
lib/puppetfile_fixtures_generator.rb,
lib/puppetfile_fixtures_generator/version.rb,
lib/puppetfile_fixtures_generator/fixtures.rb,
lib/puppetfile_fixtures_generator/puppetfile.rb

Overview

Namespace for classes and modules that handle reading and writing Puppetfiles and fixtures

Since:

  • 0.1.0

Defined Under Namespace

Classes: Fixtures, Puppetfile

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

'0.2.1'.freeze

Class Method Summary collapse

Class Method Details

.create_fixtures(puppetfile = nil, fixtures_yml = './.fixtures.yml', symlink_name = nil) ⇒ Object

Writes a YAML file conforming to [puppetlabs_spec_helper’s] (github.com/puppetlabs/puppetlabs_spec_helper) fixtures file format based off a provided Puppetfile.

Parameters:

  • puppetfile (String) (defaults to: nil)

    The path, local or absolute, to the Puppetfile. This Puppetfile will be loaded and parsed to create the fixtures YAML file.

  • fixtures_yml (String) (defaults to: './.fixtures.yml')

    The path, local or absolute, to the fixtures file to be written. The path, not the file, must exist.

  • symlink_name (String) (defaults to: nil)

    The name of the module to include as the source_dir symlink in the fixtures file.

Returns:

  • The fixtures file specified as a parameter.

Since:

  • 0.1.0



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/puppetfile_fixtures_generator.rb', line 27

def self.create_fixtures(puppetfile = nil, fixtures_yml = './.fixtures.yml', symlink_name = nil)
  modules = nil

  unless puppetfile.nil?
    pf = PuppetfileFixturesGenerator::Puppetfile.new(puppetfile)
    modules = pf.modules_hash
  end

  # write fixtures
  fixtures = PuppetfileFixturesGenerator::Fixtures.new(fixtures_yml, modules, symlink_name)
  fixtures.write
end

.diff(puppetfile, fixtures) ⇒ Array

Takes a puppetfile and a fixtures file, converts themk to hashes, diffs the hashes, and returns the results.

Parameters:

  • puppetfile (String)

    The path, local or absolute, to the Puppetfile. This Puppetfile will be loaded and parsed to create the fixtures YAML file.

  • fixtures (String)

    The path, local or absolute, to the fixtures file to be written. The path, not the file, must exist.

Returns:

  • (Array)

    The results of self.hash_differ

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
58
# File 'lib/puppetfile_fixtures_generator.rb', line 50

def self.diff(puppetfile, fixtures)
  pf = PuppetfileFixturesGenerator::Puppetfile.new(puppetfile)
  fx = PuppetfileFixturesGenerator::Fixtures.new(fixtures)

  pf_modules = pf.modules_hash['repositories'].to_a
  fx_modules = fx.modules_hash['fixtures']['repositories'].to_a

  hash_differ(pf_modules, fx_modules)
end

.hash_differ(hash1, hash2) ⇒ Array

Takes two hashes, diffs them, and returns results

Parameters:

  • hash1 (Hash)

    First hash to diff

  • hash2 (Hash)

    Second hash to diff

Returns:

  • (Array)

    First element in array is a boolean for whether the files had differences. Second element is a hash of differences.

Since:

  • 0.1.0



70
71
72
73
74
# File 'lib/puppetfile_fixtures_generator.rb', line 70

def self.hash_differ(hash1, hash2)
  result = hash1 == hash2
  return [result, {}] if result
  [result, Hash[*(hash2.size > hash1.size ? hash2 - hash1 : hash1 - hash2).flatten]]
end