File: deprecation_logger.rb

package info (click to toggle)
ruby-sshkit 1.21.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 700 kB
  • sloc: ruby: 3,522; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 521 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'set'

module SSHKit
  class DeprecationLogger
    def initialize(out)
      @out = out
      @previous_warnings = Set.new
    end

    def log(message)
      return if @out.nil?
      warning_msg = "[Deprecated] #{message}\n"
      caller_line = caller.find { |line| !line.include?('lib/sshkit') }
      warning_msg << "    (Called from #{caller_line})\n" unless caller_line.nil?
      @out << warning_msg unless @previous_warnings.include?(warning_msg)
      @previous_warnings << warning_msg
    end
  end
end