Module: SanitizeEmail::Deprecation
- Included in:
- SanitizeEmail, Config
- Defined in:
- lib/sanitize_email/deprecation.rb
Class Attribute Summary collapse
-
.deprecate_in_silence ⇒ Object
Returns the value of attribute deprecate_in_silence.
Instance Method Summary collapse
-
#deprecated(name, replacement = nil) ⇒ Object
Deprecate a defined method.
-
#deprecated_alias(name, replacement) ⇒ Object
Define a deprecated alias for a method.
- #deprecation(name, replacement = nil) ⇒ Object
Class Attribute Details
.deprecate_in_silence ⇒ Object
Returns the value of attribute deprecate_in_silence.
8 9 10 |
# File 'lib/sanitize_email/deprecation.rb', line 8 def deprecate_in_silence @deprecate_in_silence end |
Instance Method Details
#deprecated(name, replacement = nil) ⇒ Object
Deprecate a defined method
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sanitize_email/deprecation.rb', line 27 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| self.deprecation(name, " (please use ##{replacement})") send old_name, *args, &block end end |
#deprecated_alias(name, replacement) ⇒ Object
Define a deprecated alias for a method
16 17 18 19 20 21 22 |
# File 'lib/sanitize_email/deprecation.rb', line 16 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) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/sanitize_email/deprecation.rb', line 38 def deprecation(name, replacement = nil) unless SanitizeEmail::Deprecation.deprecate_in_silence if replacement warn "SanitizeEmail: ##{name} deprecated#{replacement}" else warn "SanitizeEmail: ##{name} deprecated" end end end |