summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/warnings.rb
blob: 7e26feaa017ddb98356f3464563cfade704156fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Methods to help with handling warnings.
module Puppet::Util::Warnings
  module_function

  def notice_once(msg)
    Puppet::Util::Warnings.maybe_log(msg, self.class) { Puppet.notice msg }
  end


  def warnonce(msg)
    Puppet::Util::Warnings.maybe_log(msg, self.class) { Puppet.warning msg }
  end

  def clear_warnings
    @stampwarnings = {}
    nil
  end

  protected

  def self.maybe_log(message, klass)
    @stampwarnings ||= {}
    @stampwarnings[klass] ||= []
    return nil if @stampwarnings[klass].include? message
    yield
    @stampwarnings[klass] << message
    nil
  end
end