module SanitizeEmail::Deprecation

Provides tools that allow methods to be deprecated with new releases of the gem. See www.seejohncode.com/2012/01/09/deprecating-methods-in-ruby/

Attributes

deprecate_in_silence[RW]

Public Instance Methods

deprecated(name, replacement = nil) click to toggle source

Deprecate a defined method @param [Symbol] name - name of deprecated method @param [Symbol] replacement - name of the desired replacement

# File lib/sanitize_email/deprecation.rb, line 30
def deprecated(name, replacement = nil)
  # Replace old method
  old_name = :"#{name}_without_deprecation"
  alias_method old_name, name
  # And replace it with a wrapped version
  define_method(name) do |*args, &block|
    deprecation(name, " (please use ##{replacement})")
    send old_name, *args, &block
  end
end
deprecated_alias(name, replacement) click to toggle source

Define a deprecated alias for a method @param [Symbol] name - name of method to define @param [Symbol] replacement - name of method to (alias)

# File lib/sanitize_email/deprecation.rb, line 19
def deprecated_alias(name, replacement)
  # Create a wrapped version
  define_method(name) do |*args, &block|
    warn "SanitizeEmail: ##{name} deprecated (please use ##{replacement})" unless SanitizeEmail::Deprecation.deprecate_in_silence
    send replacement, *args, &block
  end
end
deprecation(name, replacement = nil) click to toggle source
# File lib/sanitize_email/deprecation.rb, line 41
def deprecation(name, replacement = nil)
  if replacement
    deprecation_warning_message("SanitizeEmail: ##{name} deprecated#{replacement}")
  else
    deprecation_warning_message("SanitizeEmail: ##{name} deprecated")
  end
end
deprecation_warning_message(message) click to toggle source
# File lib/sanitize_email/deprecation.rb, line 49
def deprecation_warning_message(message)
  warn message unless SanitizeEmail::Deprecation.deprecate_in_silence
end