Module: PuppetRakeTasks::DepChecker::Helpers

Included in:
Resolver, Resolver::Ignores, Resolver::Report
Defined in:
lib/puppet_rake_tasks/depchecker/helpers.rb

Overview

General helpers for various methods.

Class Method Summary collapse

Class Method Details

.compare_values(ignore_value, incident_value) ⇒ Boolean

Compare values by converting symbols to strings or by using regexes to match if the ignore_value is one.



23
24
25
26
27
28
29
30
31
# File 'lib/puppet_rake_tasks/depchecker/helpers.rb', line 23

def compare_values(ignore_value, incident_value)
  if ignore_value.is_a?(Regexp)
    !ignore_value.match(incident_value.to_s).nil?
  else
    incident_value = incident_value.is_a?(Symbol) ? incident_value.to_s : incident_value
    ignore_value = ignore_value.is_a?(Symbol) ? ignore_value.to_s : ignore_value
    incident_value == ignore_value
  end
end

.normalize_path(path) ⇒ Array

Normalize paths split by File::PATH_SEPARATOR by making sure it always returns an array of paths.



10
11
12
13
14
15
16
# File 'lib/puppet_rake_tasks/depchecker/helpers.rb', line 10

def normalize_path(path)
  if path.is_a?(String)
    path.split(File::PATH_SEPARATOR)
  else
    [path].flatten
  end
end

.swat_hash(hash, glue = '.', prefix = nil) ⇒ Hash<Symbol, Any>

Swats hash keys and turns them into symbols. See example for what swatting is.

Examples:

Swatting a hash.

swat_hash({
  'foo' => {
    'bar' => 'rab',
    'foo' => {
      'super' => 'nested'
    },
  },
  'extra' => 'value'
}, '_') #=>
{
  :foo_bar => 'rab',
  :foo_foo_super => 'nested',
  :extra => 'value'
}


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/puppet_rake_tasks/depchecker/helpers.rb', line 55

def swat_hash(hash, glue = '.', prefix = nil)
  prefix = prefix.nil? ? '' : "#{prefix}#{glue}"
  intermediate = {}
  hash.each do |k, v|
    if v.is_a?(Hash)
      intermediate.merge!(swat_hash(v, glue, "#{prefix}#{k}"))
    else
      intermediate["#{prefix}#{k}".to_sym] = v
    end
  end
  intermediate
end