module Vagrant::Util::CommandDeprecation

Automatically add deprecation notices to commands

Public Class Methods

included(klass) click to toggle source
# File lib/vagrant/util/command_deprecation.rb, line 15
def self.included(klass)
  klass.class_eval do
    class << self
      if method_defined?(:synopsis)
        alias_method :non_deprecated_synopsis, :synopsis

        def synopsis
          if !non_deprecated_synopsis.to_s.empty?
            "#{non_deprecated_synopsis} [DEPRECATED]"
          else
            non_deprecated_synopsis
          end
        end
      end
    end
    alias_method :non_deprecated_execute, :execute

    def execute(*args, &block)
      @env[:ui].warn(I18n.t("vagrant.commands.deprecated",
        name: deprecation_command_name
      ) + "\n")
      non_deprecated_execute(*args, &block)
    end
  end
end
synopsis() click to toggle source
# File lib/vagrant/util/command_deprecation.rb, line 21
def synopsis
  if !non_deprecated_synopsis.to_s.empty?
    "#{non_deprecated_synopsis} [DEPRECATED]"
  else
    non_deprecated_synopsis
  end
end

Public Instance Methods

deprecation_command_name() click to toggle source

@return [String] generated name of command

# File lib/vagrant/util/command_deprecation.rb, line 7
def deprecation_command_name
  name_parts = self.class.name.split("::")
  [
    name_parts[1].sub('Command', ''),
    name_parts[3]
  ].compact.map(&:downcase).join(" ")
end
execute(*args, &block) click to toggle source
# File lib/vagrant/util/command_deprecation.rb, line 32
def execute(*args, &block)
  @env[:ui].warn(I18n.t("vagrant.commands.deprecated",
    name: deprecation_command_name
  ) + "\n")
  non_deprecated_execute(*args, &block)
end