Module: RailsOnboarding::Deprecation

Defined in:
lib/rails_onboarding/deprecation.rb

Overview

Deprecation warnings utility module Provides consistent deprecation warnings across the gem

Class Method Summary collapse

Class Method Details

.deprecate_config(option, replacement: nil, version: nil) ⇒ Object

Deprecate a configuration option

Parameters:

  • option (String)

    The deprecated configuration option

  • replacement (String) (defaults to: nil)

    The replacement option

  • version (String) (defaults to: nil)

    The version when it will be removed



41
42
43
44
45
46
47
48
# File 'lib/rails_onboarding/deprecation.rb', line 41

def deprecate_config(option, replacement: nil, version: nil)
  message = "Configuration option '#{option}' is deprecated"
  message += " and will be removed in version #{version}" if version
  message += ". Use '#{replacement}' instead" if replacement
  message += "."

  warn(message, version: version)
end

.deprecate_format(format, new_format: nil, version: nil) ⇒ Object

Deprecate a data format

Parameters:

  • format (String)

    The deprecated format description

  • new_format (String) (defaults to: nil)

    The new format description

  • version (String) (defaults to: nil)

    The version when support will be removed



54
55
56
57
58
59
60
61
# File 'lib/rails_onboarding/deprecation.rb', line 54

def deprecate_format(format, new_format: nil, version: nil)
  message = "#{format} is deprecated"
  message += " and support will be removed in version #{version}" if version
  message += ". Please migrate to: #{new_format}" if new_format
  message += "."

  warn(message, version: version)
end

.deprecate_method(old_method, new_method: nil, version: nil) ⇒ Object

Deprecate a method call

Parameters:

  • old_method (String)

    The deprecated method name

  • new_method (String) (defaults to: nil)

    The replacement method name

  • version (String) (defaults to: nil)

    The version when it will be removed



28
29
30
31
32
33
34
35
# File 'lib/rails_onboarding/deprecation.rb', line 28

def deprecate_method(old_method, new_method: nil, version: nil)
  message = "#{old_method} is deprecated"
  message += " and will be removed in version #{version}" if version
  message += ". Use #{new_method} instead" if new_method
  message += "."

  warn(message, version: version)
end

.warn(message, version: nil) ⇒ Object

Issue a deprecation warning

Parameters:

  • message (String)

    The deprecation message

  • version (String) (defaults to: nil)

    The version when the feature will be removed



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails_onboarding/deprecation.rb', line 11

def warn(message, version: nil)
  full_message = "[DEPRECATION] #{message}"
  full_message += " It will be removed in version #{version}." if version

  if defined?(ActiveSupport::Deprecation)
    # Use the default deprecator instance
    deprecator = ActiveSupport::Deprecation._instance || ActiveSupport::Deprecation.new
    deprecator.warn(full_message)
  else
    Rails.logger.warn(full_message) if defined?(Rails)
  end
end