Module: Sequel::Deprecation

Defined in:
lib/sequel/deprecated.rb

Overview

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backtrace_filterObject

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.



30
31
32
# File 'lib/sequel/deprecated.rb', line 30

def backtrace_filter
  @backtrace_filter
end

.outputObject

Where deprecation messages should be output, must respond to puts. $stderr by default.



33
34
35
# File 'lib/sequel/deprecated.rb', line 33

def output
  @output
end

.prefixObject

Where deprecation messages should be prefixed with ("SEQUEL DEPRECATION WARNING: " by default).



36
37
38
# File 'lib/sequel/deprecated.rb', line 36

def prefix
  @prefix
end

Class Method Details

.deprecate(method, instead = nil) ⇒ Object

Print the message and possibly backtrace to the output.



41
42
43
44
# File 'lib/sequel/deprecated.rb', line 41

def self.deprecate(_method, _instead=nil)
  # Sequel 5 will drop ruby 1.8 support completely, so it doesn't make sense to issue deprecation
  # warnings on ruby 1.8.
end

.deprecate_constant(mod, constant) ⇒ Object

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.



71
72
73
74
75
# File 'lib/sequel/deprecated.rb', line 71

def self.deprecate_constant(mod, constant)
  if RUBY_VERSION > '2.3'
    mod.deprecate_constant(constant)
  end
end