From d2874064f4f90df13b66debdedddc9866ac24576 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 5 Jan 2015 18:29:01 -0500 Subject: [PATCH] Use .key? instead of .has_key? --- lib/vagrant/action/builtin/box_add.rb | 4 ++-- lib/vagrant/action/builtin/config_validate.rb | 2 +- lib/vagrant/action/builtin/graceful_halt.rb | 2 +- lib/vagrant/action/builtin/mixin_synced_folders.rb | 2 +- lib/vagrant/action/builtin/provision.rb | 6 +++--- lib/vagrant/action/runner.rb | 2 +- lib/vagrant/capability_host.rb | 2 +- lib/vagrant/config/loader.rb | 6 +++--- lib/vagrant/config/v1/loader.rb | 4 ++-- lib/vagrant/config/v1/root.rb | 2 +- lib/vagrant/config/v2/loader.rb | 4 ++-- lib/vagrant/config/v2/root.rb | 10 +++++----- lib/vagrant/environment.rb | 14 +++++++------- lib/vagrant/machine.rb | 2 +- lib/vagrant/plugin/manager.rb | 2 +- lib/vagrant/plugin/state_file.rb | 2 +- lib/vagrant/plugin/v2/plugin.rb | 2 +- lib/vagrant/registry.rb | 9 +++++---- lib/vagrant/ui.rb | 12 ++++++------ lib/vagrant/util/platform.rb | 2 +- plugins/commands/destroy/command.rb | 2 +- .../commands/plugin/action/plugin_exists_check.rb | 2 +- plugins/commands/up/command.rb | 4 ++-- plugins/communicators/ssh/communicator.rb | 2 +- plugins/guests/darwin/cap/rsync.rb | 2 +- plugins/guests/freebsd/cap/rsync.rb | 2 +- plugins/guests/linux/cap/rsync.rb | 2 +- plugins/kernel_v2/config/vm.rb | 14 +++++++------- .../docker/action/host_machine_sync_folders.rb | 4 ++-- .../virtualbox/action/prepare_nfs_settings.rb | 2 +- plugins/providers/virtualbox/action/set_name.rb | 4 ++-- plugins/providers/virtualbox/driver/base.rb | 4 ++-- plugins/providers/virtualbox/driver/version_4_0.rb | 2 +- plugins/providers/virtualbox/driver/version_4_1.rb | 2 +- plugins/providers/virtualbox/driver/version_4_2.rb | 6 +++--- plugins/providers/virtualbox/driver/version_4_3.rb | 2 +- .../providers/virtualbox/model/forwarded_port.rb | 2 +- plugins/provisioners/docker/config.rb | 4 ++-- plugins/synced_folders/nfs/synced_folder.rb | 8 ++++---- plugins/synced_folders/rsync/command/rsync_auto.rb | 2 +- test/unit/vagrant/action/warden_test.rb | 2 +- .../util/hash_with_indifferent_access_test.rb | 2 +- 42 files changed, 84 insertions(+), 83 deletions(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 13688bae5..deed8b9ef 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -369,7 +369,7 @@ module Vagrant # # @return [Hash] def downloader(url, env, **opts) - opts[:ui] = true if !opts.has_key?(:ui) + opts[:ui] = true if !opts.key?(:ui) temp_path = env[:tmp_path].join("box" + Digest::SHA1.hexdigest(url)) @logger.info("Downloading box: #{url} => #{temp_path}") @@ -409,7 +409,7 @@ module Vagrant end def download(url, env, **opts) - opts[:ui] = true if !opts.has_key?(:ui) + opts[:ui] = true if !opts.key?(:ui) d = downloader(url, env, **opts) diff --git a/lib/vagrant/action/builtin/config_validate.rb b/lib/vagrant/action/builtin/config_validate.rb index e4fd44cdd..3c4461a10 100644 --- a/lib/vagrant/action/builtin/config_validate.rb +++ b/lib/vagrant/action/builtin/config_validate.rb @@ -11,7 +11,7 @@ module Vagrant end def call(env) - if !env.has_key?(:config_validate) || env[:config_validate] + if !env.key?(:config_validate) || env[:config_validate] errors = env[:machine].config.validate(env[:machine]) if errors && !errors.empty? diff --git a/lib/vagrant/action/builtin/graceful_halt.rb b/lib/vagrant/action/builtin/graceful_halt.rb index 5ccd8389d..33f6cfb9b 100644 --- a/lib/vagrant/action/builtin/graceful_halt.rb +++ b/lib/vagrant/action/builtin/graceful_halt.rb @@ -24,7 +24,7 @@ module Vagrant def call(env) graceful = true - graceful = !env[:force_halt] if env.has_key?(:force_halt) + graceful = !env[:force_halt] if env.key?(:force_halt) # By default, we didn't succeed. env[:result] = false diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index da8437dee..5a44c5ac8 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -129,7 +129,7 @@ module Vagrant # If we have folders with the "default" key, then determine the # most appropriate implementation for this. - if folders.has_key?("") && !folders[""].empty? + if folders.key?("") && !folders[""].empty? default_impl = default_synced_folder_type(machine, plugins) if !default_impl types = plugins.to_hash.keys.map { |t| t.to_s }.sort.join(", ") diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 2163a2c6a..02868c735 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -24,13 +24,13 @@ module Vagrant # Tracks whether we were configured to provision config_enabled = true - config_enabled = env[:provision_enabled] if env.has_key?(:provision_enabled) + config_enabled = env[:provision_enabled] if env.key?(:provision_enabled) # Check if we already provisioned, and if so, disable the rest provision_enabled = true ignore_sentinel = true - if env.has_key?(:provision_ignore_sentinel) + if env.key?(:provision_ignore_sentinel) ignore_sentinel = env[:provision_ignore_sentinel] end if ignore_sentinel @@ -69,7 +69,7 @@ module Vagrant end # Store the value so that other actions can use it - env[:provision_enabled] = provision_enabled if !env.has_key?(:provision_enabled) + env[:provision_enabled] = provision_enabled if !env.key?(:provision_enabled) # Ask the provisioners to modify the configuration if needed provisioner_instances(env).each do |p, _| diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index 6d4a2e409..bfb187709 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -49,7 +49,7 @@ module Vagrant # Run the action chain in a busy block, marking the environment as # interrupted if a SIGINT occurs, and exiting cleanly once the # chain has been run. - ui = environment[:ui] if environment.has_key?(:ui) + ui = environment[:ui] if environment.key?(:ui) int_callback = lambda do if environment[:interrupted] ui.error I18n.t("vagrant.actions.runner.exit_immediately") if ui diff --git a/lib/vagrant/capability_host.rb b/lib/vagrant/capability_host.rb index e3b579a49..47491deef 100644 --- a/lib/vagrant/capability_host.rb +++ b/lib/vagrant/capability_host.rb @@ -165,7 +165,7 @@ module Vagrant @cap_logger.debug("Checking in: #{host_name}") caps = @cap_caps[host_name] - if caps && caps.has_key?(cap_name) + if caps && caps.key?(cap_name) @cap_logger.debug("Found cap: #{cap_name} in #{host_name}") return caps[cap_name] end diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index f57b5d31e..35b0d0828 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -49,7 +49,7 @@ module Vagrant # Gather the procs for every source, since that is what we care about. procs = [] sources.each do |source| - if !@proc_cache.has_key?(source) + if !@proc_cache.key?(source) # Load the procs for this source and cache them. This caching # avoids the issue where a file may have side effects when loading # and loading it multiple times causes unexpected behavior. @@ -92,10 +92,10 @@ module Vagrant errors = [] order.each do |key| - next if !@sources.has_key?(key) + next if !@sources.key?(key) @sources[key].each do |version, proc| - if !@config_cache.has_key?(proc) + if !@config_cache.key?(proc) @logger.debug("Loading from: #{key} (evaluating)") # Get the proper version loader for this version and load diff --git a/lib/vagrant/config/v1/loader.rb b/lib/vagrant/config/v1/loader.rb index 910ae3dda..e26c88e44 100644 --- a/lib/vagrant/config/v1/loader.rb +++ b/lib/vagrant/config/v1/loader.rb @@ -60,7 +60,7 @@ module Vagrant new_keys = new_state["keys"] keys = {} old_keys.each do |key, old_value| - if new_keys.has_key?(key) + if new_keys.key?(key) # We need to do a merge, which we expect to be available # on the config class itself. keys[key] = old_value.merge(new_keys[key]) @@ -72,7 +72,7 @@ module Vagrant new_keys.each do |key, new_value| # Add in the keys that the new class has that we haven't merged. - if !keys.has_key?(key) + if !keys.key?(key) keys[key] = new_value.dup end end diff --git a/lib/vagrant/config/v1/root.rb b/lib/vagrant/config/v1/root.rb index 1f7db9763..975a9e4d3 100644 --- a/lib/vagrant/config/v1/root.rb +++ b/lib/vagrant/config/v1/root.rb @@ -20,7 +20,7 @@ module Vagrant # used for Vagrant and load the proper configuration classes for # each. def method_missing(name, *args) - return @keys[name] if @keys.has_key?(name) + return @keys[name] if @keys.key?(name) config_klass = @config_map[name.to_sym] if config_klass diff --git a/lib/vagrant/config/v2/loader.rb b/lib/vagrant/config/v2/loader.rb index 1c3bc0224..2f5b6cbac 100644 --- a/lib/vagrant/config/v2/loader.rb +++ b/lib/vagrant/config/v2/loader.rb @@ -70,7 +70,7 @@ module Vagrant new_keys = new_state["keys"] keys = {} old_keys.each do |key, old_value| - if new_keys.has_key?(key) + if new_keys.key?(key) # We need to do a merge, which we expect to be available # on the config class itself. keys[key] = old_value.merge(new_keys[key]) @@ -82,7 +82,7 @@ module Vagrant new_keys.each do |key, new_value| # Add in the keys that the new class has that we haven't merged. - if !keys.has_key?(key) + if !keys.key?(key) keys[key] = new_value.dup end end diff --git a/lib/vagrant/config/v2/root.rb b/lib/vagrant/config/v2/root.rb index f64129dad..f4a18c10b 100644 --- a/lib/vagrant/config/v2/root.rb +++ b/lib/vagrant/config/v2/root.rb @@ -22,7 +22,7 @@ module Vagrant # used for Vagrant and load the proper configuration classes for # each. def method_missing(name, *args) - return @keys[name] if @keys.has_key?(name) + return @keys[name] if @keys.key?(name) config_klass = @config_map[name.to_sym] if config_klass @@ -41,7 +41,7 @@ module Vagrant # mutate itself. def finalize! @config_map.each do |key, klass| - if !@keys.has_key?(key) + if !@keys.key?(key) @keys[key] = klass.new end end @@ -102,9 +102,9 @@ module Vagrant # This sets the internal state. This is used by the core to do some # merging logic and shouldn't be used by the general public. def __set_internal_state(state) - @config_map = state["config_map"] if state.has_key?("config_map") - @keys = state["keys"] if state.has_key?("keys") - @missing_key_calls = state["missing_key_calls"] if state.has_key?("missing_key_calls") + @config_map = state["config_map"] if state.key?("config_map") + @keys = state["keys"] if state.key?("keys") + @missing_key_calls = state["missing_key_calls"] if state.key?("missing_key_calls") end end end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index acda0c178..b57092b03 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -80,7 +80,7 @@ module Vagrant }.merge(opts || {}) # Set the default working directory to look for the vagrantfile - opts[:cwd] ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD") + opts[:cwd] ||= ENV["VAGRANT_CWD"] if ENV.key?("VAGRANT_CWD") opts[:cwd] ||= Dir.pwd opts[:cwd] = Pathname.new(opts[:cwd]) if !opts[:cwd].directory? @@ -94,7 +94,7 @@ module Vagrant # Set the Vagrantfile name up. We append "Vagrantfile" and "vagrantfile" so that # those continue to work as well, but anything custom will take precedence. opts[:vagrantfile_name] ||= ENV["VAGRANT_VAGRANTFILE"] if \ - ENV.has_key?("VAGRANT_VAGRANTFILE") + ENV.key?("VAGRANT_VAGRANTFILE") opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if \ opts[:vagrantfile_name] && !opts[:vagrantfile_name].is_a?(Array) @@ -307,7 +307,7 @@ module Vagrant # @return [Symbol] Name of the default provider. def default_provider(**opts) opts[:exclude] = Set.new(opts[:exclude]) if opts[:exclude] - opts[:force_default] = true if !opts.has_key?(:force_default) + opts[:force_default] = true if !opts.key?(:force_default) default = ENV["VAGRANT_DEFAULT_PROVIDER"] default = nil if default == "" @@ -351,15 +351,15 @@ module Vagrant # Skip providers that can't be defaulted, unless they're in our # config, in which case someone made our decision for us. - if !config.has_key?(key) - next if popts.has_key?(:defaultable) && !popts[:defaultable] + if !config.key?(key) + next if popts.key?(:defaultable) && !popts[:defaultable] end # The priority is higher if it is in our config. Otherwise, it is # the priority it set PLUS the length of the config to make sure it # is never higher than the configuration keys. priority = popts[:priority] - priority = config[key] + max_priority if config.has_key?(key) + priority = config[key] + max_priority if config.key?(key) ordered << [priority, key, impl, popts] end @@ -596,7 +596,7 @@ module Vagrant @machines.delete(cache_key) end - if @machines.has_key?(cache_key) + if @machines.key?(cache_key) @logger.info("Returning cached machine: #{name} (#{provider})") return @machines[cache_key] end diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 636bd0b56..03ca19f07 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -157,7 +157,7 @@ module Vagrant # Determine whether we lock or not lock = true - lock = opts.delete(:lock) if opts.has_key?(:lock) + lock = opts.delete(:lock) if opts.key?(:lock) # Extra env keys are the remaining opts extra_env = opts.dup diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb index 0cd71c8ba..dfaab2ecf 100644 --- a/lib/vagrant/plugin/manager.rb +++ b/lib/vagrant/plugin/manager.rb @@ -143,7 +143,7 @@ module Vagrant # If we already have a newer version in our list of installed, # then ignore it - next if installed_map.has_key?(spec.name) && + next if installed_map.key?(spec.name) && installed_map[spec.name].version >= spec.version installed_map[spec.name] = spec diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb index 4a39a52bc..f41da1b86 100644 --- a/lib/vagrant/plugin/state_file.rb +++ b/lib/vagrant/plugin/state_file.rb @@ -61,7 +61,7 @@ module Vagrant # # @return [Boolean] def has_plugin?(name) - @data["installed"].has_key?(name) + @data["installed"].key?(name) end # Remove a plugin that is installed from the state file. diff --git a/lib/vagrant/plugin/v2/plugin.rb b/lib/vagrant/plugin/v2/plugin.rb index a39b3cf10..025032fd9 100644 --- a/lib/vagrant/plugin/v2/plugin.rb +++ b/lib/vagrant/plugin/v2/plugin.rb @@ -88,7 +88,7 @@ module Vagrant end # By default, the command is primary - opts[:primary] = true if !opts.has_key?(:primary) + opts[:primary] = true if !opts.key?(:primary) # Register the command components.commands.register(name.to_sym) do diff --git a/lib/vagrant/registry.rb b/lib/vagrant/registry.rb index f3c86edec..d84a745a5 100644 --- a/lib/vagrant/registry.rb +++ b/lib/vagrant/registry.rb @@ -22,8 +22,8 @@ module Vagrant # This will evaluate the block given to `register` and return the # resulting value. def get(key) - return nil if !@items.has_key?(key) - return @results_cache[key] if @results_cache.has_key?(key) + return nil if !@items.key?(key) + return @results_cache[key] if @results_cache.key?(key) @results_cache[key] = @items[key].call end alias :[] :get @@ -31,9 +31,10 @@ module Vagrant # Checks if the given key is registered with the registry. # # @return [Boolean] - def has_key?(key) - @items.has_key?(key) + def key?(key) + @items.key?(key) end + alias_method :has_key?, :key? # Returns an array populated with the keys of this object. # diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 4b47c3e1f..a84448a1c 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -136,9 +136,9 @@ module Vagrant # Setup the options so that the new line is suppressed opts ||= {} - opts[:echo] = true if !opts.has_key?(:echo) - opts[:new_line] = false if !opts.has_key?(:new_line) - opts[:prefix] = false if !opts.has_key?(:prefix) + opts[:echo] = true if !opts.key?(:echo) + opts[:new_line] = false if !opts.key?(:new_line) + opts[:prefix] = false if !opts.key?(:prefix) # Output the data say(:info, message, opts) @@ -249,7 +249,7 @@ module Vagrant class_eval <<-CODE def #{method}(message, *args, **opts) super(message) - if !@ui.opts.has_key?(:bold) && !opts.has_key?(:bold) + if !@ui.opts.key?(:bold) && !opts.key?(:bold) opts[:bold] = #{method.inspect} != :detail && \ #{method.inspect} != :ask end @@ -284,7 +284,7 @@ module Vagrant opts = self.opts.merge(opts) prefix = "" - if !opts.has_key?(:prefix) || opts[:prefix] + if !opts.key?(:prefix) || opts[:prefix] prefix = OUTPUT_PREFIX prefix = " " * OUTPUT_PREFIX.length if \ type == :detail || type == :ask || opts[:prefix_spaces] @@ -294,7 +294,7 @@ module Vagrant return message if prefix.empty? target = @prefix - target = opts[:target] if opts.has_key?(:target) + target = opts[:target] if opts.key?(:target) # Get the lines. The first default is because if the message # is an empty string, then we want to still use the empty string. diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index d2b399616..c452eb295 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -148,7 +148,7 @@ module Vagrant # output. def terminal_supports_colors? if windows? - return true if ENV.has_key?("ANSICON") + return true if ENV.key?("ANSICON") return true if cygwin? return true if ENV["TERM"] == "cygwin" return false diff --git a/plugins/commands/destroy/command.rb b/plugins/commands/destroy/command.rb index e7a2f603f..141bfd38b 100644 --- a/plugins/commands/destroy/command.rb +++ b/plugins/commands/destroy/command.rb @@ -32,7 +32,7 @@ module VagrantPlugins :destroy, force_confirm_destroy: options[:force]) total += 1 - declined += 1 if action_env.has_key?(:force_confirm_destroy_result) && + declined += 1 if action_env.key?(:force_confirm_destroy_result) && action_env[:force_confirm_destroy_result] == false end diff --git a/plugins/commands/plugin/action/plugin_exists_check.rb b/plugins/commands/plugin/action/plugin_exists_check.rb index 7a369976e..b7b7b9623 100644 --- a/plugins/commands/plugin/action/plugin_exists_check.rb +++ b/plugins/commands/plugin/action/plugin_exists_check.rb @@ -12,7 +12,7 @@ module VagrantPlugins def call(env) installed = Vagrant::Plugin::Manager.instance.installed_plugins - if !installed.has_key?(env[:plugin_name]) + if !installed.key?(env[:plugin_name]) raise Vagrant::Errors::PluginNotInstalled, name: env[:plugin_name] end diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index d7b3bd7dc..826bea0ae 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -60,8 +60,8 @@ module VagrantPlugins if names.empty? autostart = false @env.vagrantfile.machine_names_and_options.each do |n, o| - autostart = true if o.has_key?(:autostart) - o[:autostart] = true if !o.has_key?(:autostart) + autostart = true if o.key?(:autostart) + o[:autostart] = true if !o.key?(:autostart) names << n.to_s if o[:autostart] end diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 35506e31e..64455042b 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -320,7 +320,7 @@ module VagrantPlugins raise Vagrant::Errors::SSHNotReady if ssh_info.nil? # Default some options - opts[:retries] = 5 if !opts.has_key?(:retries) + opts[:retries] = 5 if !opts.key?(:retries) # Build the options we'll use to initiate the connection via Net::SSH common_connect_opts = { diff --git a/plugins/guests/darwin/cap/rsync.rb b/plugins/guests/darwin/cap/rsync.rb index e98d6e5ae..7e5d6d9a5 100644 --- a/plugins/guests/darwin/cap/rsync.rb +++ b/plugins/guests/darwin/cap/rsync.rb @@ -17,7 +17,7 @@ module VagrantPlugins end def self.rsync_post(machine, opts) - if opts.has_key?(:chown) && !opts[:chown] + if opts.key?(:chown) && !opts[:chown] return end diff --git a/plugins/guests/freebsd/cap/rsync.rb b/plugins/guests/freebsd/cap/rsync.rb index 2876b5943..c8fb36006 100644 --- a/plugins/guests/freebsd/cap/rsync.rb +++ b/plugins/guests/freebsd/cap/rsync.rb @@ -31,7 +31,7 @@ module VagrantPlugins end def self.rsync_post(machine, opts) - if opts.has_key?(:chown) && !opts[:chown] + if opts.key?(:chown) && !opts[:chown] return end diff --git a/plugins/guests/linux/cap/rsync.rb b/plugins/guests/linux/cap/rsync.rb index 113b18dd0..424d20f46 100644 --- a/plugins/guests/linux/cap/rsync.rb +++ b/plugins/guests/linux/cap/rsync.rb @@ -17,7 +17,7 @@ module VagrantPlugins end def self.rsync_post(machine, opts) - if opts.has_key?(:chown) && !opts[:chown] + if opts.key?(:chown) && !opts[:chown] return end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index da2440c52..87bc8d71b 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -96,7 +96,7 @@ module VagrantPlugins end other_defined_vms.each do |key, subvm| - if !new_defined_vms.has_key?(key) + if !new_defined_vms.key?(key) new_defined_vms[key] = subvm.clone else new_defined_vms[key].config_procs.concat(subvm.config_procs) @@ -197,7 +197,7 @@ module VagrantPlugins options ||= {} options[:guestpath] = guestpath.to_s.gsub(/\/$/, '') options[:hostpath] = hostpath - options[:disabled] = false if !options.has_key?(:disabled) + options[:disabled] = false if !options.key?(:disabled) options = (@__synced_folders[options[:guestpath]] || {}). merge(options.dup) @@ -247,7 +247,7 @@ module VagrantPlugins id = "#{type}-#{id}" # Merge in the previous settings if we have them. - if @__networks.has_key?(id) + if @__networks.key?(id) options = @__networks[id][1].merge(options) end @@ -279,13 +279,13 @@ module VagrantPlugins def provision(name, **options, &block) type = name - if options.has_key?(:type) + if options.key?(:type) type = options.delete(:type) else name = nil end - if options.has_key?(:id) + if options.key?(:id) puts "Setting `id` on a provisioner is deprecated. Please use the" puts "new syntax of `config.vm.provision \"name\", type: \"type\"" puts "where \"name\" is the replacement for `id`. This will be" @@ -306,8 +306,8 @@ module VagrantPlugins end prov.preserve_order = !!options.delete(:preserve_order) if \ - options.has_key?(:preserve_order) - prov.run = options.delete(:run) if options.has_key?(:run) + options.key?(:preserve_order) + prov.run = options.delete(:run) if options.key?(:run) prov.add_config(options, &block) nil end diff --git a/plugins/providers/docker/action/host_machine_sync_folders.rb b/plugins/providers/docker/action/host_machine_sync_folders.rb index 2c10df337..9a6f03893 100644 --- a/plugins/providers/docker/action/host_machine_sync_folders.rb +++ b/plugins/providers/docker/action/host_machine_sync_folders.rb @@ -22,7 +22,7 @@ module VagrantPlugins def call(env) return @app.call(env) if !env[:machine].provider.host_vm? - if !env.has_key?(:host_machine_sync_folders) + if !env.key?(:host_machine_sync_folders) env[:host_machine_sync_folders] = true end @@ -115,7 +115,7 @@ module VagrantPlugins # Add this synced folder onto the new config if we haven't # already shared it before. - if !existing_ids.has_key?(id) + if !existing_ids.key?(id) # A bit of a hack for VirtualBox to mount our # folder as transient. This can be removed once # the VirtualBox synced folder mechanism is smarter. diff --git a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb index c5f95af1f..d3edf3e93 100644 --- a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb +++ b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb @@ -24,7 +24,7 @@ module VagrantPlugins } folders = synced_folders(env[:machine], **opts) - if folders.has_key?(:nfs) + if folders.key?(:nfs) @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") add_ips_to_env!(env) end diff --git a/plugins/providers/virtualbox/action/set_name.rb b/plugins/providers/virtualbox/action/set_name.rb index 3cbcf131a..0e80f4591 100644 --- a/plugins/providers/virtualbox/action/set_name.rb +++ b/plugins/providers/virtualbox/action/set_name.rb @@ -32,9 +32,9 @@ module VagrantPlugins # Verify the name is not taken vms = env[:machine].provider.driver.read_vms raise Vagrant::Errors::VMNameExists, name: name if \ - vms.has_key?(name) && vms[name] != env[:machine].id + vms.key?(name) && vms[name] != env[:machine].id - if vms.has_key?(name) + if vms.key?(name) @logger.info("Not setting the name because our name is already set.") else env[:ui].info(I18n.t( diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 3002418f7..da019eae8 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -30,8 +30,8 @@ module VagrantPlugins # On Windows, we use the VBOX_INSTALL_PATH environmental # variable to find VBoxManage. - if ENV.has_key?("VBOX_INSTALL_PATH") || - ENV.has_key?("VBOX_MSI_INSTALL_PATH") + if ENV.key?("VBOX_INSTALL_PATH") || + ENV.key?("VBOX_MSI_INSTALL_PATH") # Get the path. path = ENV["VBOX_INSTALL_PATH"] || ENV["VBOX_MSI_INSTALL_PATH"] @logger.debug("VBOX_INSTALL_PATH value: #{path}") diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 04070b559..a29193842 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -445,7 +445,7 @@ module VagrantPlugins folder[:name], "--hostpath", folder[:hostpath]] - args << "--transient" if folder.has_key?(:transient) && folder[:transient] + args << "--transient" if folder.key?(:transient) && folder[:transient] execute("sharedfolder", "add", @uuid, *args) end end diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index d8ffe3a0e..c22042b6b 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -450,7 +450,7 @@ module VagrantPlugins folder[:name], "--hostpath", folder[:hostpath]] - args << "--transient" if folder.has_key?(:transient) && folder[:transient] + args << "--transient" if folder.key?(:transient) && folder[:transient] # Enable symlinks on the shared folder execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index 9299874a5..d976d973c 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -189,9 +189,9 @@ module VagrantPlugins # we use the block form of sub here to ensure that if the specified_name happens to end with a number (which is fairly likely) then # we won't end up having the character sequence of a \ followed by a number be interpreted as a back reference. For example, if # specified_name were "abc123", then "\\abc123\\".reverse would be "\\321cba\\", and the \3 would be treated as a back reference by the sub - disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse) { "\\#{specified_name}\\".reverse }.reverse # Replace only last occurrence + disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse) { "\\#{specified_name}\\".reverse }.reverse # Replace only last occurrence else - disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurrence + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurrence end end @@ -481,7 +481,7 @@ module VagrantPlugins folder[:name], "--hostpath", folder[:hostpath]] - args << "--transient" if folder.has_key?(:transient) && folder[:transient] + args << "--transient" if folder.key?(:transient) && folder[:transient] # Enable symlinks on the shared folder execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 552a49b26..28e6539d4 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -498,7 +498,7 @@ module VagrantPlugins folder[:name], "--hostpath", folder[:hostpath]] - args << "--transient" if folder.has_key?(:transient) && folder[:transient] + args << "--transient" if folder.key?(:transient) && folder[:transient] # Enable symlinks on the shared folder execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") diff --git a/plugins/providers/virtualbox/model/forwarded_port.rb b/plugins/providers/virtualbox/model/forwarded_port.rb index 2229519f7..03107408e 100644 --- a/plugins/providers/virtualbox/model/forwarded_port.rb +++ b/plugins/providers/virtualbox/model/forwarded_port.rb @@ -51,7 +51,7 @@ module VagrantPlugins options ||= {} @auto_correct = false - @auto_correct = options[:auto_correct] if options.has_key?(:auto_correct) + @auto_correct = options[:auto_correct] if options.key?(:auto_correct) @adapter = (options[:adapter] || 1).to_i @guest_ip = options[:guest_ip] || nil @host_ip = options[:host_ip] || nil diff --git a/plugins/provisioners/docker/config.rb b/plugins/provisioners/docker/config.rb index c96e97305..7e6c37787 100644 --- a/plugins/provisioners/docker/config.rb +++ b/plugins/provisioners/docker/config.rb @@ -70,8 +70,8 @@ module VagrantPlugins @__containers.each do |name, params| params[:image] ||= name - params[:auto_assign_name] = true if !params.has_key?(:auto_assign_name) - params[:daemonize] = true if !params.has_key?(:daemonize) + params[:auto_assign_name] = true if !params.key?(:auto_assign_name) + params[:daemonize] = true if !params.key?(:daemonize) end end end diff --git a/plugins/synced_folders/nfs/synced_folder.rb b/plugins/synced_folders/nfs/synced_folder.rb index f2cdbd0dd..7cf51aabe 100644 --- a/plugins/synced_folders/nfs/synced_folder.rb +++ b/plugins/synced_folders/nfs/synced_folder.rb @@ -64,7 +64,7 @@ module VagrantPlugins export_folders = folders.dup export_folders.keys.each do |id| opts = export_folders[id] - if opts.has_key?(:nfs_export) && !opts[:nfs_export] + if opts.key?(:nfs_export) && !opts[:nfs_export] export_folders.delete(id) end end @@ -117,7 +117,7 @@ module VagrantPlugins def prepare_folder(machine, opts) opts[:map_uid] = prepare_permission(machine, :uid, opts) opts[:map_gid] = prepare_permission(machine, :gid, opts) - opts[:nfs_udp] = true if !opts.has_key?(:nfs_udp) + opts[:nfs_udp] = true if !opts.key?(:nfs_udp) opts[:nfs_version] ||= 3 # We use a CRC32 to generate a 32-bit checksum so that the @@ -128,11 +128,11 @@ module VagrantPlugins # Prepares the UID/GID settings for a single folder. def prepare_permission(machine, perm, opts) key = "map_#{perm}".to_sym - return nil if opts.has_key?(key) && opts[key].nil? + return nil if opts.key?(key) && opts[key].nil? # The options on the hash get priority, then the default # values - value = opts.has_key?(key) ? opts[key] : machine.config.nfs.send(key) + value = opts.key?(key) ? opts[key] : machine.config.nfs.send(key) return value if value != :auto # Get UID/GID from folder if we've made it this far diff --git a/plugins/synced_folders/rsync/command/rsync_auto.rb b/plugins/synced_folders/rsync/command/rsync_auto.rb index 802fb6e58..b2a4adc0b 100644 --- a/plugins/synced_folders/rsync/command/rsync_auto.rb +++ b/plugins/synced_folders/rsync/command/rsync_auto.rb @@ -83,7 +83,7 @@ module VagrantPlugins folders.each do |id, folder_opts| # If we marked this folder to not auto sync, then # don't do it. - next if folder_opts.has_key?(:auto) && !folder_opts[:auto] + next if folder_opts.key?(:auto) && !folder_opts[:auto] hostpath = folder_opts[:hostpath] hostpath = File.expand_path(hostpath, machine.env.root_path) diff --git a/test/unit/vagrant/action/warden_test.rb b/test/unit/vagrant/action/warden_test.rb index b9758be7a..9c668e371 100644 --- a/test/unit/vagrant/action/warden_test.rb +++ b/test/unit/vagrant/action/warden_test.rb @@ -87,6 +87,6 @@ describe Vagrant::Action::Warden do expect { instance.call(data) }.to raise_error(SystemExit) # The recover should not have been called - expect(data.has_key?(:recover)).not_to be + expect(data.key?(:recover)).not_to be end end diff --git a/test/unit/vagrant/util/hash_with_indifferent_access_test.rb b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb index 397773eed..fdebeb374 100644 --- a/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +++ b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb @@ -22,7 +22,7 @@ describe Vagrant::Util::HashWithIndifferentAccess do it "allows indifferent key lookup" do instance["foo"] = "bar" expect(instance.key?(:foo)).to be - expect(instance.has_key?(:foo)).to be + expect(instance.key?(:foo)).to be expect(instance.include?(:foo)).to be expect(instance.member?(:foo)).to be end