diff options
Diffstat (limited to 'lib/chef')
44 files changed, 102 insertions, 89 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index e917a4eaf7..ab19e6571e 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -120,9 +120,10 @@ class Chef end def set_specific_recipes - Chef::Config[:specific_recipes] = - cli_arguments.map { |file| File.expand_path(file) } if - cli_arguments.respond_to?(:map) + if cli_arguments.respond_to?(:map) + Chef::Config[:specific_recipes] = + cli_arguments.map { |file| File.expand_path(file) } + end end # Initialize and configure the logger. @@ -342,7 +343,7 @@ class Chef message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" cause = e.cause if e.respond_to?(:cause) - while cause != nil + until cause.nil? message << "\n\n>>>> Caused by #{cause.class}: #{cause}\n#{cause.backtrace.join("\n")}" cause = cause.respond_to?(:cause) ? cause.cause : nil end diff --git a/lib/chef/application/windows_service_manager.rb b/lib/chef/application/windows_service_manager.rb index 6f81dccc67..fd0ce0b174 100644 --- a/lib/chef/application/windows_service_manager.rb +++ b/lib/chef/application/windows_service_manager.rb @@ -126,10 +126,12 @@ class Chef :password => @password, :dependencies => @dependencies ) - ::Win32::Service.configure( - :service_name => @service_name, - :delayed_start => @delayed_start - ) unless @delayed_start.nil? + unless @delayed_start.nil? + ::Win32::Service.configure( + :service_name => @service_name, + :delayed_start => @delayed_start + ) + end puts "Service '#{@service_name}' has successfully been installed." end when "status" diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 6b3e830f8d..9893cf7245 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -326,7 +326,7 @@ class Chef else relative << path[1] end - relative = relative + file[:path].split("/") + relative += file[:path].split("/") file["url"] = ChefZero::RestBase.build_uri(request.base_uri, relative) end end diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb index 2d887f4780..1b6884514a 100644 --- a/lib/chef/chef_fs/command_line.rb +++ b/lib/chef/chef_fs/command_line.rb @@ -229,7 +229,7 @@ class Chef end end - if old_value == :none || (old_value == nil && !old_entry.exists?) + if old_value == :none || (old_value.nil? && !old_entry.exists?) return [ [ :added, old_entry, new_entry, old_value, new_value ] ] elsif new_value == :none return [ [ :deleted, old_entry, new_entry, old_value, new_value ] ] diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index 71ef53c9e5..dce58ecdb8 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -52,7 +52,7 @@ class Chef ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE end else - Chef::Log.debug("No chefignore file found at #@ignore_file no files will be ignored") + Chef::Log.debug("No chefignore file found at #{@ignore_file} no files will be ignored") end ignore_globs end diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index af8b2e043e..d253c956b2 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -308,7 +308,7 @@ class Chef begin @metadata.from_file(file) rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Error evaluating metadata.rb for #@inferred_cookbook_name in " + file) + Chef::Log.error("Error evaluating metadata.rb for #{@inferred_cookbook_name} in " + file) raise end end @@ -317,7 +317,7 @@ class Chef begin @metadata.from_json(IO.read(file)) rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in " + file) + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) raise end end @@ -336,7 +336,7 @@ class Chef # metadata contains a name key. @metadata.name(data["cookbook_name"]) unless data["metadata"].key?("name") rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in " + file) + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) raise end end @@ -347,7 +347,7 @@ class Chef data = Chef::JSONCompat.parse(IO.read(uploaded_cookbook_version_file)) @frozen = data["frozen?"] rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in #{uploaded_cookbook_version_file}") + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in #{uploaded_cookbook_version_file}") raise end end diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index b2f3db9b8e..c3698f3315 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -862,12 +862,12 @@ INVALID return if !options[:choice].is_a?(Array) || options[:choice].empty? if options[:default].is_a?(String) && options[:default] != "" - raise ArgumentError, "Default must be one of your choice values!" if options[:choice].index(options[:default]) == nil + raise ArgumentError, "Default must be one of your choice values!" if options[:choice].index(options[:default]).nil? end if options[:default].is_a?(Array) && !options[:default].empty? options[:default].each do |val| - raise ArgumentError, "Default values must be a subset of your choice values!" if options[:choice].index(val) == nil + raise ArgumentError, "Default values must be a subset of your choice values!" if options[:choice].index(val).nil? end end end diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb index bff77fa13b..a965b43c61 100644 --- a/lib/chef/cookbook_loader.rb +++ b/lib/chef/cookbook_loader.rb @@ -137,7 +137,7 @@ class Chef alias :key? :has_key? def each - @cookbooks_by_name.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |cname| + @cookbooks_by_name.keys.sort_by(&:to_s).each do |cname| yield(cname, @cookbooks_by_name[cname]) end end diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index 0e676145eb..df3bce6167 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -462,8 +462,10 @@ class Chef end def validate_data_collector_server_url! - raise Chef::Exceptions::ConfigurationError, - "Chef::Config[:data_collector][:server_url] is empty. Please supply a valid URL." if data_collector_server_url.empty? + if data_collector_server_url.empty? + raise Chef::Exceptions::ConfigurationError, + "Chef::Config[:data_collector][:server_url] is empty. Please supply a valid URL." + end begin uri = URI(data_collector_server_url) @@ -471,8 +473,10 @@ class Chef raise Chef::Exceptions::ConfigurationError, "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is not a valid URI." end - raise Chef::Exceptions::ConfigurationError, - "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is a URI with no host. Please supply a valid URL." if uri.host.nil? + if uri.host.nil? + raise Chef::Exceptions::ConfigurationError, + "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is a URI with no host. Please supply a valid URL." + end end end end diff --git a/lib/chef/data_collector/messages.rb b/lib/chef/data_collector/messages.rb index f63242f85e..c0683534a9 100644 --- a/lib/chef/data_collector/messages.rb +++ b/lib/chef/data_collector/messages.rb @@ -82,12 +82,14 @@ class Chef "deprecations" => reporter_data[:deprecations], } - message["error"] = { - "class" => run_status.exception.class, - "message" => run_status.exception.message, - "backtrace" => run_status.exception.backtrace, - "description" => reporter_data[:error_descriptions], - } if run_status.exception + if run_status.exception + message["error"] = { + "class" => run_status.exception.class, + "message" => run_status.exception.message, + "backtrace" => run_status.exception.backtrace, + "description" => reporter_data[:error_descriptions], + } + end message end diff --git a/lib/chef/encrypted_data_bag_item.rb b/lib/chef/encrypted_data_bag_item.rb index e696199c63..d30c7945e9 100644 --- a/lib/chef/encrypted_data_bag_item.rb +++ b/lib/chef/encrypted_data_bag_item.rb @@ -121,7 +121,7 @@ class Chef::EncryptedDataBagItem # def self.load(data_bag, name, secret = nil) raw_hash = Chef::DataBagItem.load(data_bag, name) - secret = secret || self.load_secret + secret ||= self.load_secret self.new(raw_hash, secret) end diff --git a/lib/chef/encrypted_data_bag_item/decryptor.rb b/lib/chef/encrypted_data_bag_item/decryptor.rb index 773ff4e154..f35611d185 100644 --- a/lib/chef/encrypted_data_bag_item/decryptor.rb +++ b/lib/chef/encrypted_data_bag_item/decryptor.rb @@ -93,7 +93,7 @@ class Chef::EncryptedDataBagItem plaintext << openssl_decryptor.final rescue OpenSSL::Cipher::CipherError => e # if the key length is less than 255 characters, and it contains slashes, we think it may be a path. - raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{ (@key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : '' }" + raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{(@key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : ''}" end end @@ -144,7 +144,7 @@ class Chef::EncryptedDataBagItem plaintext << openssl_decryptor.final rescue OpenSSL::Cipher::CipherError => e # if the key length is less than 255 characters, and it contains slashes, we think it may be a path. - raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{ ( @key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : '' }" + raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{( @key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : ''}" end end diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index c41df768b9..eb335b0237 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -171,7 +171,7 @@ class Chef unless params[:cookbook_version].nil? params[:cookbook_version].each do |index, cookbook_constraint_spec| unless cookbook_constraint_spec.nil? || cookbook_constraint_spec.size == 0 - valid = valid && update_cookbook_constraint_from_param(index, cookbook_constraint_spec) + valid &&= update_cookbook_constraint_from_param(index, cookbook_constraint_spec) end end end diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index c933841726..2d6dcef17e 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -76,10 +76,10 @@ class Chef class Group < RuntimeError; end class Link < RuntimeError; end class Mount < RuntimeError; end - class Reboot < Exception; end - class RebootPending < Exception; end + class Reboot < Exception; end # rubocop:disable Lint/InheritException + class RebootPending < Exception; end # rubocop:disable Lint/InheritException class RebootFailed < Mixlib::ShellOut::ShellCommandFailed; end - class ClientUpgraded < Exception; end + class ClientUpgraded < Exception; end # rubocop:disable Lint/InheritException class PrivateKeyMissing < RuntimeError; end class CannotWritePrivateKey < RuntimeError; end class RoleNotFound < RuntimeError; end @@ -159,7 +159,7 @@ class Chef # Thrown when Win32 API layer binds to non-existent Win32 function. Occurs # when older versions of Windows don't support newer Win32 API functions. - class Win32APIFunctionNotImplemented < NotImplementedError; end + class Win32APIFunctionNotImplemented < NotImplementedError; end # rubocop:disable Lint/InheritException # Attempting to run windows code on a not-windows node class Win32NotWindows < RuntimeError; end class WindowsNotAdmin < RuntimeError; end @@ -196,7 +196,7 @@ class Chef class InvalidVersionConstraint < ArgumentError; end # Version constraints are not allowed in chef-solo - class IllegalVersionConstraint < NotImplementedError; end + class IllegalVersionConstraint < NotImplementedError; end # rubocop:disable Lint/InheritException class MetadataNotValid < StandardError; end class MetadataNotFound < StandardError diff --git a/lib/chef/file_access_control/unix.rb b/lib/chef/file_access_control/unix.rb index 1746db44d3..0dfbff8422 100644 --- a/lib/chef/file_access_control/unix.rb +++ b/lib/chef/file_access_control/unix.rb @@ -117,13 +117,13 @@ class Chef end def gid_from_resource(resource) - return nil if resource == nil || resource.group.nil? + return nil if resource.nil? || resource.group.nil? if resource.group.kind_of?(String) diminished_radix_complement( Etc.getgrnam(resource.group).gid ) elsif resource.group.kind_of?(Integer) resource.group else - Chef::Log.error("The `group` parameter of the #@resource resource is set to an invalid value (#{resource.owner.inspect})") + Chef::Log.error("The `group` parameter of the #{@resource} resource is set to an invalid value (#{resource.owner.inspect})") raise ArgumentError, "cannot resolve #{resource.group.inspect} to gid, group must be a string or integer" end rescue ArgumentError @@ -168,7 +168,7 @@ class Chef end def mode_from_resource(res) - return nil if res == nil || res.mode.nil? + return nil if res.nil? || res.mode.nil? (res.mode.respond_to?(:oct) ? res.mode.oct : res.mode.to_i) & 007777 end @@ -264,13 +264,13 @@ class Chef end def uid_from_resource(resource) - return nil if resource == nil || resource.owner.nil? + return nil if resource.nil? || resource.owner.nil? if resource.owner.kind_of?(String) diminished_radix_complement( Etc.getpwnam(resource.owner).uid ) elsif resource.owner.kind_of?(Integer) resource.owner else - Chef::Log.error("The `owner` parameter of the #@resource resource is set to an invalid value (#{resource.owner.inspect})") + Chef::Log.error("The `owner` parameter of the #{@resource} resource is set to an invalid value (#{resource.owner.inspect})") raise ArgumentError, "cannot resolve #{resource.owner.inspect} to uid, owner must be a string or integer" end rescue ArgumentError diff --git a/lib/chef/formatters/error_description.rb b/lib/chef/formatters/error_description.rb index 8d7f940181..ece33bdd49 100644 --- a/lib/chef/formatters/error_description.rb +++ b/lib/chef/formatters/error_description.rb @@ -48,7 +48,7 @@ class Chef display_section("Platform:", RUBY_PLATFORM, out) end - def for_json() + def for_json { "title" => @title, "sections" => @sections, diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb index 460744ea2a..9a000136e6 100644 --- a/lib/chef/http/basic_client.rb +++ b/lib/chef/http/basic_client.rb @@ -111,7 +111,7 @@ class Chef # match no_proxy with a fuzzy matcher, rather than letting Net::HTTP # do it. http_client = http_client_builder.new(host, port, nil) - http_client.proxy_port = nil if http_client.proxy_address == nil + http_client.proxy_port = nil if http_client.proxy_address.nil? if url.scheme == HTTPS configure_ssl(http_client) diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index 43d015dcc4..5b2d7d3517 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -83,7 +83,7 @@ class Chef # Check to ensure we have a valid source of cookbooks before continuing # @install_path = File.expand_path(Array(config[:cookbook_path]).first) - ui.info "Installing #@cookbook_name to #{@install_path}" + ui.info "Installing #{@cookbook_name} to #{@install_path}" @repo = CookbookSCMRepo.new(@install_path, ui, config) #cookbook_path = File.join(vendor_path, name_args[0]) diff --git a/lib/chef/knife/core/cookbook_scm_repo.rb b/lib/chef/knife/core/cookbook_scm_repo.rb index e909066b02..2c678e07b9 100644 --- a/lib/chef/knife/core/cookbook_scm_repo.rb +++ b/lib/chef/knife/core/cookbook_scm_repo.rb @@ -122,7 +122,7 @@ class Chef git("branch --no-color").stdout.lines.any? { |l| l =~ /\s#{Regexp.escape(branch_name)}(?:\s|$)/ } end - def get_current_branch() + def get_current_branch ref = git("symbolic-ref HEAD").stdout ref.chomp.split("/")[2] end diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index 0e07dd704f..e9a9a236c2 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -138,7 +138,7 @@ class Chef end def ask_question(question, opts = {}) - question = question + "[#{opts[:default]}] " if opts[:default] + question += "[#{opts[:default]}] " if opts[:default] if opts[:default] && config[:defaults] opts[:default] diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb index c0b2d0d0c5..7016b08ff7 100644 --- a/lib/chef/mixin/deep_merge.rb +++ b/lib/chef/mixin/deep_merge.rb @@ -75,7 +75,7 @@ class Chef end when Array if dest.kind_of?(Array) - dest = dest | source + dest |= source else dest = source end diff --git a/lib/chef/mixin/wide_string.rb b/lib/chef/mixin/wide_string.rb index 4342ef1650..ef7828e2d8 100644 --- a/lib/chef/mixin/wide_string.rb +++ b/lib/chef/mixin/wide_string.rb @@ -34,7 +34,7 @@ class Chef ustring = (ustring + "").force_encoding("UTF-8") if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8" # ensure we have the double-null termination Windows Wide likes - ustring = ustring + "\000\000" if ustring.length == 0 || ustring[-1].chr != "\000" + ustring += "\000\000" if ustring.length == 0 || ustring[-1].chr != "\000" # encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode ustring = begin diff --git a/lib/chef/node.rb b/lib/chef/node.rb index f2a5cab1f5..087a173880 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -111,7 +111,7 @@ class Chef # Set the name of this Node, or return the current name. def name(arg = nil) - if arg != nil + if !arg.nil? validate( { :name => arg }, { :name => { :kind_of => String, diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index d051bb1d92..a5c5e0d267 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -65,7 +65,7 @@ class Chef # this can't be recovered from in why-run mode, because nothing that # we do in the course of a run is likely to create a valid target_revision # if we can't resolve it up front. - a.assertion { target_revision != nil } + a.assertion { !target_revision.nil? } a.failure_message Chef::Exceptions::UnresolvableGitReference, "Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. " + "Verify your (case-sensitive) repository URL and revision.\n" + diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index 49e825e39f..e00f3290fa 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -210,7 +210,7 @@ class Chef end def device_real - if @real_device == nil + if @real_device.nil? if @new_resource.device_type == :device @real_device = @new_resource.device else diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb index 69ecf2ddb9..a25ac9539f 100644 --- a/lib/chef/provider/osx_profile.rb +++ b/lib/chef/provider/osx_profile.rb @@ -44,8 +44,10 @@ class Chef ) @new_profile_hash = get_profile_hash(@new_resource.profile) - @new_profile_hash["PayloadUUID"] = - config_uuid(@new_profile_hash) if @new_profile_hash + if @new_profile_hash + @new_profile_hash["PayloadUUID"] = + config_uuid(@new_profile_hash) + end if @new_profile_hash @new_profile_identifier = @new_profile_hash["PayloadIdentifier"] diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 048807dd05..ecf3dbecb5 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -56,7 +56,7 @@ class Chef def check_resource_semantics! # FIXME: this is not universally true and subclasses are needing to override this and no-ops it. It should be turned into # another "subclass_directive" and the apt and yum providers should declare that they need this behavior. - if new_resource.package_name.is_a?(Array) && new_resource.source != nil + if new_resource.package_name.is_a?(Array) && !new_resource.source.nil? raise Chef::Exceptions::InvalidResourceSpecification, "You may not specify both multipackage and source" end end @@ -196,7 +196,7 @@ class Chef end action :reconfig do - if @current_resource.version == nil + if @current_resource.version.nil? Chef::Log.debug("#{@new_resource} is NOT installed - nothing to do") return end diff --git a/lib/chef/provider/package/easy_install.rb b/lib/chef/provider/package/easy_install.rb index 926f609092..a9c6e2a792 100644 --- a/lib/chef/provider/package/easy_install.rb +++ b/lib/chef/provider/package/easy_install.rb @@ -122,7 +122,7 @@ class Chef def remove_package(name, version) Chef.deprecated(:easy_install, "The easy_install package provider is deprecated and will be removed in Chef 13.") - run_command(:command => "#{easy_install_binary_path }#{expand_options(@new_resource.options)} -m #{name}") + run_command(:command => "#{easy_install_binary_path}#{expand_options(@new_resource.options)} -m #{name}") end def purge_package(name, version) diff --git a/lib/chef/provider/package/powershell.rb b/lib/chef/provider/package/powershell.rb index 5206b5b696..caeda6d412 100644 --- a/lib/chef/provider/package/powershell.rb +++ b/lib/chef/provider/package/powershell.rb @@ -60,7 +60,7 @@ class Chef # Removes the package for the version passed and if no version is passed, then all installed versions of the package are removed def remove_package(names, versions) names.each_with_index do |name, index| - if versions && versions[index] != nil + if versions && !versions[index].nil? powershell_out( "Uninstall-Package '#{name}' -Force -ForceBootstrap -RequiredVersion #{versions[index]}", { :timeout => @new_resource.timeout }) else version = "0" @@ -78,7 +78,7 @@ class Chef def build_candidate_versions versions = [] new_resource.package_name.each_with_index do |name, index| - if new_resource.version && new_resource.version[index] != nil + if new_resource.version && !new_resource.version[index].nil? version = powershell_out("(Find-Package '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip() else version = powershell_out("(Find-Package '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip() @@ -95,7 +95,7 @@ class Chef def build_current_versions version_list = [] new_resource.package_name.each_with_index do |name, index| - if new_resource.version && new_resource.version[index] != nil + if new_resource.version && !new_resource.version[index].nil? version = powershell_out("(Get-Package -Name '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip() else version = powershell_out("(Get-Package -Name '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip() diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb index edad45c3e4..6965052723 100644 --- a/lib/chef/provider/package/zypper.rb +++ b/lib/chef/provider/package/zypper.rb @@ -144,7 +144,7 @@ class Chef end end - def gpg_checks() + def gpg_checks case Chef::Config[:zypper_check_gpg] when true "" diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb index 64c89aac6d..7c6f91cdca 100644 --- a/lib/chef/provider/route.rb +++ b/lib/chef/provider/route.rb @@ -134,7 +134,7 @@ class Chef::Provider::Route < Chef::Provider Chef::Log.debug("#{@new_resource} route already active - nothing to do") else command = generate_command(:add) - converge_by ("run #{ command } to add route") do + converge_by ("run #{command} to add route") do run_command( :command => command ) Chef::Log.info("#{@new_resource} added") end @@ -147,7 +147,7 @@ class Chef::Provider::Route < Chef::Provider def action_delete if is_running command = generate_command(:delete) - converge_by ("run #{ command } to delete route ") do + converge_by ("run #{command} to delete route ") do run_command( :command => command ) Chef::Log.info("#{@new_resource} removed") end @@ -186,7 +186,7 @@ class Chef::Provider::Route < Chef::Provider end conf.each do |k, v| network_file_name = "/etc/sysconfig/network-scripts/route-#{k}" - converge_by ("write route route.#{k}\n#{conf[k]} to #{ network_file_name }") do + converge_by ("write route route.#{k}\n#{conf[k]} to #{network_file_name}") do network_file = ::File.new(network_file_name, "w") network_file.puts(conf[k]) Chef::Log.debug("#{@new_resource} writing route.#{k}\n#{conf[k]}") diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb index 2fd32e37aa..e34227036a 100644 --- a/lib/chef/provider/service/arch.rb +++ b/lib/chef/provider/service/arch.rb @@ -66,7 +66,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init end end - def enable_service() + def enable_service new_daemons = [] entries = daemons @@ -92,7 +92,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init end end - def disable_service() + def disable_service new_daemons = [] entries = daemons diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb index 76d8c1d17b..9746dfdef0 100644 --- a/lib/chef/provider/service/freebsd.rb +++ b/lib/chef/provider/service/freebsd.rb @@ -74,7 +74,7 @@ class Chef end requirements.assert(:start, :enable, :reload, :restart) do |a| - a.assertion { service_enable_variable_name != nil } + a.assertion { !service_enable_variable_name.nil? } a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar" # No recovery in whyrun mode - the init file is present but not correct. end diff --git a/lib/chef/provider/service/gentoo.rb b/lib/chef/provider/service/gentoo.rb index 8fb6d1f9af..7bb57113ac 100644 --- a/lib/chef/provider/service/gentoo.rb +++ b/lib/chef/provider/service/gentoo.rb @@ -61,11 +61,11 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init end end - def enable_service() + def enable_service shell_out!("/sbin/rc-update add #{@new_resource.service_name} default") end - def disable_service() + def disable_service shell_out!("/sbin/rc-update del #{@new_resource.service_name} default") end end diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb index 76b2ee7477..c3dca10495 100644 --- a/lib/chef/provider/service/insserv.rb +++ b/lib/chef/provider/service/insserv.rb @@ -45,12 +45,12 @@ class Chef current_resource end - def enable_service() + def enable_service shell_out!("/sbin/insserv -r -f #{new_resource.service_name}") shell_out!("/sbin/insserv -d -f #{new_resource.service_name}") end - def disable_service() + def disable_service shell_out!("/sbin/insserv -r -f #{new_resource.service_name}") end end diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 648cd9748b..8663e7eabf 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -181,7 +181,7 @@ class Chef end def set_service_status - return if @plist == nil || @service_label.to_s.empty? + return if @plist.nil? || @service_label.to_s.empty? cmd = "launchctl list #{@service_label}" res = shell_out_as_user(cmd) diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb index c60bbf170c..780337e1b6 100644 --- a/lib/chef/provider/service/openbsd.rb +++ b/lib/chef/provider/service/openbsd.rb @@ -72,7 +72,7 @@ class Chef end requirements.assert(:start, :enable, :reload, :restart) do |a| - a.assertion { init_command && builtin_service_enable_variable_name != nil } + a.assertion { init_command && !builtin_service_enable_variable_name.nil? } a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar" # No recovery in whyrun mode - the init file is present but not correct. end diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 200a2d3400..21ab678706 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -109,7 +109,7 @@ class Chef (run_levels.nil? || run_levels.empty?) ? "" : "--level #{run_levels.join('')} " end - def enable_service() + def enable_service unless run_levels.nil? || run_levels.empty? disable_levels = current_run_levels - run_levels shell_out! "/sbin/chkconfig --level #{disable_levels.join('')} #{new_resource.service_name} off" unless disable_levels.empty? @@ -117,7 +117,7 @@ class Chef shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} on" end - def disable_service() + def disable_service shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} off" end end diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index cf5585e5cf..3400684bc5 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -108,10 +108,12 @@ class Chef def verify_command(path, opts) # First implementation interpolated `file`; docs & RFC claim `path` # is interpolated. Until `file` can be deprecated, interpolate both. - Chef.deprecated(:verify_file, - "%{file} is deprecated in verify command and will not be "\ - "supported in Chef 13. Please use %{path} instead." - ) if @command.include?("%{file}") + if @command.include?("%{file}") + Chef.deprecated(:verify_file, + "%{file} is deprecated in verify command and will not be "\ + "supported in Chef 13. Please use %{path} instead." + ) + end command = @command % { :file => path, :path => path } interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts) interpreter.evaluate diff --git a/lib/chef/scan_access_control.rb b/lib/chef/scan_access_control.rb index f55a106e6d..0e6df30303 100644 --- a/lib/chef/scan_access_control.rb +++ b/lib/chef/scan_access_control.rb @@ -70,7 +70,7 @@ class Chef when Integer stat.uid else - Chef::Log.error("The `owner` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})") + Chef::Log.error("The `owner` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})") raise ArgumentError, "cannot resolve #{new_resource.owner.inspect} to uid, owner must be a string or integer" end end @@ -97,7 +97,7 @@ class Chef when Integer stat.gid else - Chef::Log.error("The `group` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})") + Chef::Log.error("The `group` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})") raise ArgumentError, "cannot resolve #{new_resource.group.inspect} to gid, group must be a string or integer" end end @@ -121,8 +121,8 @@ class Chef when String, Integer, nil "0#{(stat.mode & 07777).to_s(8)}" else - Chef::Log.error("The `mode` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.mode.inspect})") - raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #@new_resource" + Chef::Log.error("The `mode` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.mode.inspect})") + raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #{@new_resource}" end end diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb index be8d0b301b..43b7d1bdf9 100644 --- a/lib/chef/util/dsc/resource_store.rb +++ b/lib/chef/util/dsc/resource_store.rb @@ -74,7 +74,7 @@ class Chef found = rs.find_all do |r| name_matches = r["Name"].casecmp(name) == 0 if name_matches - module_name == nil || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0) + module_name.nil? || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0) else false end diff --git a/lib/chef/win32/memory.rb b/lib/chef/win32/memory.rb index 49dcdfbd41..2a9d5d8eb5 100644 --- a/lib/chef/win32/memory.rb +++ b/lib/chef/win32/memory.rb @@ -35,7 +35,7 @@ class Chef Chef::ReservedNames::Win32::Error.raise! end # If a block is passed, handle freeing the memory at the end - if block != nil + if !block.nil? begin yield result ensure diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 7fc3215786..8bf2bfa762 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -551,7 +551,7 @@ class Chef def set_security_descriptor_dacl(security_descriptor, acl, defaulted = false, present = nil) security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer) acl = acl.pointer if acl.respond_to?(:pointer) - present = !security_descriptor.null? if present == nil + present = !security_descriptor.null? if present.nil? unless SetSecurityDescriptorDacl(security_descriptor, present, acl, defaulted) Chef::ReservedNames::Win32::Error.raise! @@ -579,7 +579,7 @@ class Chef def self.set_security_descriptor_sacl(security_descriptor, acl, defaulted = false, present = nil) security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer) acl = acl.pointer if acl.respond_to?(:pointer) - present = !security_descriptor.null? if present == nil + present = !security_descriptor.null? if present.nil? unless SetSecurityDescriptorSacl(security_descriptor, present, acl, defaulted) Chef::ReservedNames::Win32::Error.raise! diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb index f6b88c60ce..983166ac70 100644 --- a/lib/chef/win32/security/sid.rb +++ b/lib/chef/win32/security/sid.rb @@ -50,7 +50,7 @@ class Chef end def ==(other) - other != nil && Chef::ReservedNames::Win32::Security.equal_sid(self, other) + !other.nil? && Chef::ReservedNames::Win32::Security.equal_sid(self, other) end attr_reader :pointer @@ -61,7 +61,7 @@ class Chef def account_name domain, name, use = account - (domain != nil && domain.length > 0) ? "#{domain}\\#{name}" : name + (!domain.nil? && domain.length > 0) ? "#{domain}\\#{name}" : name end def size |