Module: PuppetRakeTasks::DepChecker::Resolver::Ignores

Extended by:
Helpers
Included in:
PuppetRakeTasks::DepChecker::Resolver
Defined in:
lib/puppet_rake_tasks/depchecker/ignores.rb

Overview

Deal with management of the ignore rules you can set. You can either set all rules in one go using #ignores= or add one by one using the #ignore method.

Reference:

When referring to the 'simple name' of a puppet module, use the name without author/ in front. You can not have a module with the same name installed in your tree anyhow.

Examples:

Adding a rule for a single module.

# Ignores the stdlib version mismatch on `your_module`.
@depchecker.ignore 'your_module', { name: 'puppetlabs/stdlib', reason: :version_mismatch }

Adding a rule for a single module with regexp values.

# Ignores all modules from author `custom` that are missing.
@depchecker.ignore 'your_module', { name: %r{^custom/.*}, reason: :missing }

Adding a rule for all modules using a regexp.

# ignores a missing module for all modules that might declare it as a dependency.
@depchecker.ignore %r{.*}, { name: 'foobar/module', reason: :missing }

Loading ignores from a (yaml) file

@depchecker.ignores = YAML.load_file('.ignores.yaml')
# .ignores.yaml
# ---
# !ruby/regexp /.*/:
#   - :name: always/missing
#     :reason: :missing
# foobar:
#   - :name: !ruby/regexp /.*/
#     :reason: :version_mismatch

Instance Method Summary collapse

Methods included from Helpers

compare_values, normalize_path, swat_hash

Instance Method Details

#collect_ignores_for_module(modulename) ⇒ Array (private)

Returns array with all ignores that apply to a certain puppet module.

Parameters:

  • modulename (String)

    puppet module name. Must be in the 'simple' form.

Returns:

  • (Array)

    array with all ignores that apply to a certain puppet module.



95
96
97
98
99
100
101
102
103
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 95

def collect_ignores_for_module(modulename)
  tmp_ignores = []
  ignores.each do |k, i|
    if (k.is_a?(String) && k == modulename) || (k.is_a?(Regexp) && modulename =~ k)
      tmp_ignores += i
    end
  end
  tmp_ignores
end

#ignore(for_module, expr) ⇒ Object

Parameters:

  • for_module (String, Regexp)

    module name or regex this rule applies to.

  • expr (Hash)

    ignore expression.



50
51
52
53
54
55
56
57
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 50

def ignore(for_module, expr)
  # reset cached ignores matching modules
  (@ignores_for_module ||= {})[for_module] = nil

  # initialize if not exists
  (@ignores ||= {})[for_module] ||= []
  @ignores[for_module] << expr
end

#ignoresHash

Returns all configured ignore rules.

Returns:

  • (Hash)

    ignore rules.



61
62
63
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 61

def ignores
  @ignores ||= {}
end

#ignores=(ignores) ⇒ Object

Configure all ignore rules at once by setting a single hash. This clears the cached ignore rules for modules.

Parameters:

  • ignores (Hash)

    Hash with ignore rules.



43
44
45
46
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 43

def ignores=(ignores)
  @ignores = ignores
  @ignores_for_module = {}
end

#ignores_for_module(modulename) ⇒ Object

Returns ignore rules that might apply to the modulename and caches the result.

Parameters:

  • modulename (String)

    module name to get ignore rules for in its simple form.



67
68
69
70
71
72
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 67

def ignores_for_module(modulename)
  if (@ignores_for_module ||= {})[modulename].nil?
    @ignores_for_module[modulename] ||= collect_ignores_for_module(modulename)
  end
  @ignores_for_module[modulename]
end

#ignores_matches_incident(modulename, incident) ⇒ Object

Loop over ignores for a modulename and check if it matches the incident.

Parameters:

  • modulename (String)

    puppet module name.

  • incident (Hash)

    The module incident to check.



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet_rake_tasks/depchecker/ignores.rb', line 77

def ignores_matches_incident(modulename, incident)
  loop_ignores = ignores_for_module(modulename)
  # Look for a match, return true immediately, otherwise, false
  loop_ignores.each do |ign|
    this_ignore = true
    ign.keys.each do |k|
      compare = Helpers.compare_values(ign[k], incident[k])
      this_ignore = false unless compare
    end
    return true if this_ignore
  end
  false
end