Class: Hanami::Utils::Deprecation

Inherits:
Object
  • Object
show all
Defined in:
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



62
63
64
# File 'lib/hanami/utils/deprecation.rb', line 62

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