module Dry::Core::Deprecations

def [](tag)

def [](tag)
  Tagged.new(tag)
end

def announce(name, msg, tag: nil, uplevel: nil)

Parameters:
  • msg (String) -- additional message usually containing upgrade instructions
  • name (Object) -- what is deprecated
def announce(name, msg, tag: nil, uplevel: nil)
  # Bump the uplevel (if provided) by one to account for the uplevel calculation
  # taking place one frame deeper in `.warn`
  uplevel += 1 if uplevel
  warn(deprecation_message(name, msg), tag: tag, uplevel: uplevel)
end

def deprecated_name_message(old, new = nil, msg = nil)

Other tags:
    Api: - private
def deprecated_name_message(old, new = nil, msg = nil)
  if new
    deprecation_message(old, <<-MSG)
      Please use #{new} instead.
      #{msg}
    MSG
  else
    deprecation_message(old, msg)
  end
end

def deprecation_message(name, msg)

Other tags:
    Api: - private
def deprecation_message(name, msg)
  <<-MSG
    #{name} is deprecated and will be removed in the next major version
    #{msg}
  MSG
end

def logger(output = $stderr)

Returns:
  • (Logger) -

Parameters:
  • output (IO) -- output stream
def logger(output = $stderr)
  if defined?(@logger)
    @logger
  else
    set_logger!(output)
  end
end

def set_logger!(output = $stderr)

Other tags:
    Api: - public

Parameters:
  • logger (#warn) --
  • output (IO) -- Stream for messages

Overloads:
  • set_logger!(logger)
  • set_logger!
  • set_logger!(output)
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

def warn(msg, tag: nil, uplevel: nil)

Parameters:
  • Caller (Integer) -- frame to add to the message
  • tag (String) -- Tag to help identify the source of the warning.
  • msg (String) -- Warning string
def warn(msg, tag: nil, uplevel: nil)
  caller_info = uplevel.nil? ? nil : "#{caller_locations(uplevel + 2, 1)[0]} "
  tag = "[#{tag || "deprecated"}] "
  hint = msg.gsub(/^\s+/, "")
  logger.warn("#{caller_info}#{tag}#{hint}")
end