| Module | Sequel::Deprecation |
| In: |
lib/sequel/deprecated.rb
|
This module makes it easy to print deprecation warnings with optional backtraces to a given stream. There are a two accessors you can use to change how/where the deprecation methods are printed and whether/how backtraces should be included:
Sequel::Deprecation.output = $stderr # print deprecation messages to standard error (default)
Sequel::Deprecation.output = File.open('deprecated_calls.txt', 'wb') # use a file instead
Sequel::Deprecation.output = false # do not output deprecation messages
Sequel::Deprecation.prefix = "SEQUEL DEPRECATION WARNING: " # prefix deprecation messages with a given string (default)
Sequel::Deprecation.prefix = false # do not prefix deprecation messages
Sequel::Deprecation.backtrace_filter = false # don't include backtraces
Sequel::Deprecation.backtrace_filter = true # include full backtraces
Sequel::Deprecation.backtrace_filter = 10 # include 10 backtrace lines (default)
Sequel::Deprecation.backtrace_filter = 1 # include 1 backtrace line
Sequel::Deprecation.backtrace_filter = lambda{|line, line_no| line_no < 3 || line =~ /my_app/} # select backtrace lines to output
| backtrace_filter | [RW] | How to filter backtraces. false does not include backtraces, true includes full backtraces, an Integer includes that number of backtrace lines, and a proc is called with the backtrace line and line number to select the backtrace lines to include. The default is 10 backtrace lines. |
| output | [RW] | Where deprecation messages should be output, must respond to puts. $stderr by default. |
| prefix | [RW] | Where deprecation messages should be prefixed with ("SEQUEL DEPRECATION WARNING: " by default). |
Print the message and possibly backtrace to the output.
# File lib/sequel/deprecated.rb, line 40
40: def self.deprecate(method, instead=nil)
41: return unless output
42: message = instead ? "#{method} is deprecated and will be removed in Sequel 5.1. #{instead}." : method
43: message = "#{prefix}#{message}" if prefix
44: output.puts(message)
45: case b = backtrace_filter
46: when Integer
47: caller.each do |c|
48: b -= 1
49: output.puts(c)
50: break if b <= 0
51: end
52: when true
53: caller.each{|c| output.puts(c)}
54: when Proc
55: caller.each_with_index{|line, line_no| output.puts(line) if b.call(line, line_no)}
56: end
57: nil
58: end
If using ruby 2.3+, use Module#deprecate_constant to deprecate the constant, otherwise do nothing as the ruby implementation does not support constant deprecation.
# File lib/sequel/deprecated.rb, line 62
62: def self.deprecate_constant(mod, constant)
63: if RUBY_VERSION > '2.3'
64: mod.deprecate_constant(constant)
65: end
66: end