Sha256: 517658a6eb4e4d102ad4ba003096b7e3043a47749bfb49d0f353bbd285774d14

Contents?: true

Size: 1.8 KB

Versions: 27

Compression:

Stored size: 1.8 KB

Contents

require 'hanami/utils'

module Hanami
  module Utils
    # Prints a deprecation warning when initialized
    #
    # @since 0.3.1
    class Deprecation
      # Initialize a deprecation message and prints it to standard error.
      #
      # @param message [#to_s] a deprecation message
      #
      # @since 0.3.1
      #
      # @example 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
      #
      # @example 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
      def initialize(message)
        ::Kernel.warn("#{message} - called from: #{caller[caller_index]}.")
      end

      private

      # @api private
      def caller_index
        Utils.jruby? || Utils.rubinius? ? 1 : 2
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hanami-utils-1.3.6 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.5 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.4 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.3 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.2 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.1 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.0 lib/hanami/utils/deprecation.rb
hanami-utils-1.3.0.beta1 lib/hanami/utils/deprecation.rb
hanami-utils-1.2.0 lib/hanami/utils/deprecation.rb
hanami-utils-1.2.0.rc2 lib/hanami/utils/deprecation.rb
hanami-utils-1.2.0.rc1 lib/hanami/utils/deprecation.rb
hanami-utils-1.2.0.beta2 lib/hanami/utils/deprecation.rb
hanami-utils-1.2.0.beta1 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.2 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.1 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.0 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.0.rc1 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.0.beta3 lib/hanami/utils/deprecation.rb
hanami-utils-1.1.0.beta2 lib/hanami/utils/deprecation.rb
hanami-utils-1.0.4 lib/hanami/utils/deprecation.rb