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

Author:

  • Sylvain Daubert

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

'4.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

Parameters:

  • klass (Module)

    class/module of deprecated method

  • deprecated_method (Symbol, String)
  • new_method (Symbol, String, nil) (defaults to: nil)

    method to use instead of deprecated one

  • klass_method (Boolean) (defaults to: false)

    deprecated_method is a class method (true) or a, instance one (false)

  • remove_version (String) (defaults to: REMOVE_VERSION)

    version from which deprecated_method will no more exist.

Since:

  • 2.7.0



29
30
31
32
33
34
35
36
37
38
39
# 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}"
  complete_new_method_name = "#{base_name}#{new_method}" unless new_method.nil?

  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

Parameters:

  • klass (Module)

    deprecated class/module

  • new_klass (Module) (defaults to: nil)

    class/module to use instead of klass

  • remove_version (String) (defaults to: REMOVE_VERSION)

    version from which klass will no more exist.

Since:

  • 3.1.0



47
48
49
50
51
52
53
# File 'lib/packetgen/deprecation.rb', line 47

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

Parameters:

  • klass (Module)

    deprecated class/module

  • method (Module)

    method name

  • option (Symbol)

    option name

  • klass_method (Boolean) (defaults to: false)

    deprecated_method is a class method (true) or a, instance one (false)

  • remove_version (String) (defaults to: REMOVE_VERSION)

    version from which klass will no more exist.

Since:

  • 3.1.4



64
65
66
67
68
69
70
# File 'lib/packetgen/deprecation.rb', line 64

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.

Parameters:

  • remove_version (String)

Returns:

  • (String)

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