Newer
Older
dmpopidor / lib / cleanup / deprecators / predicate_deprecator.rb
@Bodacious Bodacious on 1 Aug 2018 1021 bytes Refactored model code for better readability
# frozen_string_literal: true

module Cleanup
  module Deprecators

    # Used to deprecate methods that are predicate methods without question mks
    #
    # There are methods in the code with non-idiomatic method names. Typically,
    # Ruby predicates are named as verbs in the infinitive with a question mark.
    #
    class PredicateDeprecator

      ##
      # Default message to display to developer when deprecated method called.
      MESSAGE = "%<deprecated_method>s is deprecated. "\
                  "Instead, you should use: %<new_method>s. "\
                  "Read #{__FILE__} for more information."

      # Message printed to STDOUT when a deprecated method is called.
      def deprecation_warning(deprecated_method, _message, _backtrace = nil)
        new_method = "#{deprecated_method.to_s}?"
        message = format(MESSAGE,
                         deprecated_method: deprecated_method,
                         new_method: new_method)
        Kernel.warn(message)
      end

    end
  end
end