Sha256: 7d306654e30ffe11a159a4fe32a61885c611579384ad1be00e62e865d6610827
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
# See http://www.seejohncode.com/2012/01/09/deprecating-methods-in-ruby/ require 'facets/module/mattr' # gives cattr module SanitizeEmail module Deprecation mattr_reader :deprecate_in_silence mattr_writer :deprecate_in_silence self.deprecate_in_silence = false # Define a deprecated alias for a method # @param [Symbol] name - name of method to define # @param [Symbol] replacement - name of method to (alias) def deprecated_alias(name, replacement) # Create a wrapped version define_method(name) do |*args, &block| warn "SanitizeEmail: ##{name} deprecated (please use ##{replacement})" unless @@deprecate_in_silence send replacement, *args, &block end end # Deprecate a defined method # @param [Symbol] name - name of deprecated method # @param [Symbol] replacement - name of the desired replacement 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| unless @@deprecate_in_silence if replacement warn "SanitizeEmail: ##{name} deprecated (please use ##{replacement})" else warn "SanitizeEmail: ##{name} deprecated" end end send old_name, *args, &block end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sanitize_email-1.0.2 | lib/sanitize_email/deprecation.rb |