Class: Hanami::Utils::Deprecation

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-utils-2.2.0.beta1/lib/hanami/utils/deprecation.rb

Overview

Prints a deprecation warning when initialized

Since:

  • 0.3.1

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Deprecation

Initialize a deprecation message and prints it to standard error.

Examples:

Direct usage

require 'hanami/utils/deprecation'

class Engine
  def old_method
    Hanami::Utils::Deprecation.new('old_method is deprecated, please use new_method')
    new_method
  end

  def new_method
    puts 'started'
  end
end

Engine.new.old_method
  # => old_method is deprecated, please use new_method - called from: test.rb:14:in `<main>'.
  # => started

Indirect usage

require 'hanami/utils/deprecation'

class Engine
  def old_method
    Hanami::Utils::Deprecation.new('old_method is deprecated, please use new_method')
    new_method
  end

  def new_method
    puts 'started'
  end
end

class Car
  def initialize
    @engine = Engine.new
  end

  def start
    @engine.old_method
  end
end

Car.new.start
  # => old_method is deprecated, please use new_method - called from: test.rb:20:in `start'.
  # => started

Parameters:

  • message (#to_s)

    a deprecation message

Since:

  • 0.3.1

def initialize(message)
  ::Kernel.warn("#{message} - called from: #{caller[caller_index]}.")
end