summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/warnings.rb
blob: 3156b412c4f91dd88fe2b54ab38f8de22d584497 (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