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
Defined Under Namespace
Classes: Fixtures, Puppetfile
Constant Summary collapse
- VERSION =
'0.2.1'.freeze
Class Method Summary collapse
-
.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.
-
.diff(puppetfile, fixtures) ⇒ Array
Takes a puppetfile and a fixtures file, converts themk to hashes, diffs the hashes, and returns the results.
-
.hash_differ(hash1, hash2) ⇒ Array
Takes two hashes, diffs them, and returns results.
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.
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.
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
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 |