Module: Dry::Core::Deprecations
- Defined in:
- lib/dry/core/deprecations.rb
Overview
An extension for issueing warnings on using deprecated methods.
Defined Under Namespace
Modules: Interface Classes: Tagged
Constant Summary collapse
- STACK =
-> { caller.find { |l| l !~ %r{(lib/dry/core)|(gems)} } }
Class Method Summary collapse
- .[](tag) ⇒ Object
-
.announce(name, msg, tag: nil) ⇒ Object
Wraps arguments with a standard message format and prints a warning.
- .deprecated_name_message(old, new = nil, msg = nil) ⇒ Object private
- .deprecation_message(name, msg) ⇒ Object private
-
.logger(output = $stderr) ⇒ Logger
Returns the logger used for printing warnings.
-
.set_logger!(output = $stderr) ⇒ Object
Sets a custom logger.
-
.warn(msg, tag: nil) ⇒ Object
Prints a warning.
Class Method Details
.[](tag) ⇒ Object
105 106 107 |
# File 'lib/dry/core/deprecations.rb', line 105 def [](tag) Tagged.new(tag) end |
.announce(name, msg, tag: nil) ⇒ Object
Wraps arguments with a standard message format and prints a warning
45 46 47 |
# File 'lib/dry/core/deprecations.rb', line 45 def announce(name, msg, tag: nil) warn((name, msg), tag: tag) end |
.deprecated_name_message(old, new = nil, msg = nil) ⇒ 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.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dry/core/deprecations.rb', line 58 def (old, new = nil, msg = nil) if new (old, <<-MSG) Please use #{new} instead. #{msg} MSG else (old, msg) end end |
.deprecation_message(name, msg) ⇒ 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.
50 51 52 53 54 55 |
# File 'lib/dry/core/deprecations.rb', line 50 def (name, msg) <<-MSG #{ name } is deprecated and will be removed in the next major version #{ msg } MSG end |
.logger(output = $stderr) ⇒ Logger
Returns the logger used for printing warnings. You can provide your own with .set_logger!
75 76 77 78 79 80 81 |
# File 'lib/dry/core/deprecations.rb', line 75 def logger(output = $stderr) if defined?(@logger) @logger else set_logger!(output) end end |
.set_logger!(output) ⇒ Object .set_logger! ⇒ Object .set_logger!(logger) ⇒ Object
Sets a custom logger. This is a global setting.
95 96 97 98 99 100 101 102 103 |
# File 'lib/dry/core/deprecations.rb', line 95 def set_logger!(output = $stderr) if output.respond_to?(:warn) @logger = output else @logger = Logger.new(output).tap do |logger| logger.formatter = proc { |_, _, _, msg| "#{ msg }\n" } end end end |
.warn(msg, tag: nil) ⇒ Object
Prints a warning
36 37 38 39 |
# File 'lib/dry/core/deprecations.rb', line 36 def warn(msg, tag: nil) tagged = "[#{tag || 'deprecated'}] #{msg.gsub(/^\s+/, '')}" logger.warn(tagged) end |