Module: Vagrant::Util::CommandDeprecation

Defined in:
lib/vagrant/util/command_deprecation.rb

Overview

Automatically add deprecation notices to commands

Defined Under Namespace

Modules: Complete

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#deprecation_command_nameString

Returns generated name of command.

Returns:

  • (String)

    generated name of command


7
8
9
10
11
12
13
# 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