Module: PacketGen::Deprecation Private

Defined in:
lib/packetgen/deprecation.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Deprecation module

Since:

  • 2.7.0

Constant Summary collapse

REMOVE_VERSION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default remove version for deprecated classes/methods

Since:

  • 3.1.0

'5.0.0'

Class Method Summary collapse

Class Method Details

.deprecated(klass, deprecated_method, new_method = nil, klass_method: false, remove_version: REMOVE_VERSION) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Warn when using a deprecated method

Since:

  • 2.7.0



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/packetgen/deprecation.rb', line 29

def self.deprecated(klass, deprecated_method, new_method=nil, klass_method: false, remove_version: REMOVE_VERSION)
  base_name = "#{klass}#{klass_method ? '.' : '#'}"
  complete_deprecated_method_name = "#{base_name}#{deprecated_method}"
  unless new_method.nil?
    complete_new_method_name = if %w[# .].any? { |punct| new_method.include?(punct) }
                                 new_method
                               else
                                 "#{base_name}#{new_method}"
                               end
  end

  file, line = caller(2..2).first.split(':')[0, 2]
  message = "#{file}:#{line}: #{complete_deprecated_method_name} is deprecated"
  message << " in favor of #{complete_new_method_name}" unless new_method.nil?
  message << '. ' << self.removed(remove_version)
  warn(message)
end

.deprecated_class(klass, new_klass = nil, remove_version: REMOVE_VERSION) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Warn when using a deprecated method

Since:

  • 3.1.0



53
54
55
56
57
58
59
# File 'lib/packetgen/deprecation.rb', line 53

def self.deprecated_class(klass, new_klass=nil, remove_version: REMOVE_VERSION)
  file, line = caller(2..2).first.split(':')[0, 2]
  message = "#{file}:#{line}: #{klass} is deprecated"
  message << " in favor of #{new_klass}" unless new_klass.nil?
  message << '. ' << self.removed(remove_version)
  warn(message)
end

.deprecated_option(klass, method, option, klass_method: false, remove_version: REMOVE_VERSION) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Warn when using a deprecated method’s option

Since:

  • 3.1.4



70
71
72
73
74
75
76
# File 'lib/packetgen/deprecation.rb', line 70

def self.deprecated_option(klass, method, option, klass_method: false, remove_version: REMOVE_VERSION)
  base_name = "#{klass}#{klass_method ? '.' : '#'}"
  method_name = "#{base_name}#{method}"
  message = "option #{option} is deprecated for method #{method_name}. "
  message << self.removed(remove_version)
  warn(message)
end

.removed(remove_version) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 3.1.4



17
18
19
# File 'lib/packetgen/deprecation.rb', line 17

def self.removed(remove_version)
  "It will be removed in PacketGen #{remove_version}"
end