diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-23 10:45:15 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-23 10:45:15 -0800 |
commit | 271d3e4f91e3d158c9112512ac75d0ca51fc928d (patch) | |
tree | 5beb5e5588db43ecac46f38725cabf5e573fd1d6 /lib | |
parent | aa7e0e05395823c66b30f1a810d1720aea3b6d72 (diff) | |
download | chef-271d3e4f91e3d158c9112512ac75d0ca51fc928d.tar.gz |
Autofixing new Perf cops in 0.37.2
6 Performance/Casecmp
18 Performance/Detect
1 Performance/RangeInclude
27 Performance/RedundantBlockCall
6 Performance/RedundantMatch
5 Performance/RedundantMerge
18 Performance/StringReplacement
Diffstat (limited to 'lib')
49 files changed, 61 insertions, 59 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 9ec553fb8a..79cb046919 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -263,7 +263,7 @@ class Chef::Application::Client < Chef::Application option :audit_mode, :long => "--audit-mode MODE", :description => "Enable audit-mode with `enabled`. Disable audit-mode with `disabled`. Skip converge and only perform audits with `audit-only`", - :proc => lambda { |mo| mo.gsub("-", "_").to_sym } + :proc => lambda { |mo| mo.tr("-", "_").to_sym } option :minimal_ohai, :long => "--minimal-ohai", diff --git a/lib/chef/chef_fs/data_handler/container_data_handler.rb b/lib/chef/chef_fs/data_handler/container_data_handler.rb index a2e277fc7a..6e578e53d6 100644 --- a/lib/chef/chef_fs/data_handler/container_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/container_data_handler.rb @@ -18,7 +18,7 @@ class Chef def verify_integrity(object, entry, &on_error) base_name = remove_dot_json(entry.name) if object["containername"] != base_name - on_error.call("Name in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['name']}')") + yield("Name in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['name']}')") end end diff --git a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb index 8ac9a520a4..3b609fad4e 100644 --- a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb @@ -45,7 +45,7 @@ class Chef def verify_integrity(object, entry, &on_error) base_name = remove_dot_json(entry.name) if object["raw_data"]["id"] != base_name - on_error.call("ID in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['raw_data']['id']}')") + yield("ID in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['raw_data']['id']}')") end end diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb index 83f56ed16d..93d54e3bee 100644 --- a/lib/chef/chef_fs/data_handler/data_handler_base.rb +++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb @@ -192,7 +192,7 @@ class Chef def verify_integrity(object, entry, &on_error) base_name = remove_dot_json(entry.name) if object["name"] != base_name - on_error.call("Name must be '#{base_name}' (is '#{object['name']}')") + yield("Name must be '#{base_name}' (is '#{object['name']}')") end end diff --git a/lib/chef/chef_fs/data_handler/organization_data_handler.rb b/lib/chef/chef_fs/data_handler/organization_data_handler.rb index 3e5528cc49..d61e4f454a 100644 --- a/lib/chef/chef_fs/data_handler/organization_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/organization_data_handler.rb @@ -21,7 +21,7 @@ class Chef def verify_integrity(object, entry, &on_error) if entry.org != object["name"] - on_error.call("Name must be '#{entry.org}' (is '#{object['name']}')") + yield("Name must be '#{entry.org}' (is '#{object['name']}')") end end end diff --git a/lib/chef/chef_fs/data_handler/policy_data_handler.rb b/lib/chef/chef_fs/data_handler/policy_data_handler.rb index 477d2bf637..47f534bfc9 100644 --- a/lib/chef/chef_fs/data_handler/policy_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/policy_data_handler.rb @@ -29,11 +29,11 @@ class Chef def verify_integrity(object_data, entry, &on_error) name, revision = name_and_revision(entry.name) if object_data["name"] != name - on_error.call("Object name '#{object_data['name']}' doesn't match entry '#{entry.name}'.") + yield("Object name '#{object_data['name']}' doesn't match entry '#{entry.name}'.") end if object_data["revision_id"] != revision - on_error.call("Object revision ID '#{object_data['revision']}' doesn't match entry '#{entry.name}'.") + yield("Object revision ID '#{object_data['revision']}' doesn't match entry '#{entry.name}'.") end end end diff --git a/lib/chef/chef_fs/data_handler/policy_group_data_handler.rb b/lib/chef/chef_fs/data_handler/policy_group_data_handler.rb index e5c430ab64..d3bdd81e25 100644 --- a/lib/chef/chef_fs/data_handler/policy_group_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/policy_group_data_handler.rb @@ -17,7 +17,7 @@ class Chef def verify_integrity(object_data, entry, &on_error) if object_data["policies"].empty? - on_error.call("Policy group #{object_data["name"]} does not have any policies in it.") + yield("Policy group #{object_data["name"]} does not have any policies in it.") end end diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb index 415556300c..e6cf735971 100644 --- a/lib/chef/chef_fs/file_system.rb +++ b/lib/chef/chef_fs/file_system.rb @@ -55,7 +55,7 @@ class Chef def list_from(entry, &block) # Include self in results if it matches if pattern.match?(entry.path) - block.call(entry) + yield(entry) end if pattern.could_match_children?(entry.path) diff --git a/lib/chef/chef_fs/file_system/chef_server/acl_dir.rb b/lib/chef/chef_fs/file_system/chef_server/acl_dir.rb index 9943aaeca7..58a32d3860 100644 --- a/lib/chef/chef_fs/file_system/chef_server/acl_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/acl_dir.rb @@ -30,7 +30,7 @@ class Chef end def make_child_entry(name, exists = nil) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || AclEntry.new(name, self, exists) end diff --git a/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb b/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb index d03164023f..b9af486203 100644 --- a/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/acls_dir.rb @@ -39,7 +39,7 @@ class Chef end def make_child_entry(name) - children.select { |child| child.name == name }.first + children.find { |child| child.name == name } end def can_have_child?(name, is_dir) diff --git a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb index 6c99d6de73..5030a0733f 100644 --- a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb @@ -119,7 +119,7 @@ class Chef end def can_have_child?(name, is_dir) - result = children.select { |child| child.name == name }.first + result = children.find { |child| child.name == name } result && !!result.dir? == !!is_dir end @@ -136,7 +136,7 @@ class Chef end def make_child_entry(name) - children.select { |child| child.name == name }.first + children.find { |child| child.name == name } end def children diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb index 020f8510b7..0b82a64a0a 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb @@ -35,7 +35,7 @@ class Chef class CookbookArtifactsDir < CookbooksDir def make_child_entry(name) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || CookbookArtifactDir.new(name, self) end diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb index 3a08768baf..d69126ce6e 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb @@ -74,7 +74,7 @@ class Chef # we need to make sure we don't rethrow the exception. (child(name) # is not supposed to fail.) begin - children.select { |child| child.name == name }.first + children.find { |child| child.name == name } rescue Chef::ChefFS::FileSystem::NotFoundError nil end @@ -101,7 +101,7 @@ class Chef container = self parts[0, parts.length - 1].each do |part| old_container = container - container = old_container.children.select { |child| part == child.name }.first + container = old_container.children.find { |child| part == child.name } if !container container = CookbookSubdir.new(part, old_container, segment_info[:ruby_only], segment_info[:recursive]) old_container.add_child(container) diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_subdir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_subdir.rb index 913cf1a5e2..01297a39ba 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_subdir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_subdir.rb @@ -47,7 +47,7 @@ class Chef end def make_child_entry(name) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || NonexistentFSObject.new(name, self) end diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb index 75d7150f8e..72cefe44eb 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb @@ -41,7 +41,7 @@ class Chef include Chef::Mixin::FileClass def make_child_entry(name) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || CookbookDir.new(name, self) end diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb b/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb index 9246d8e2b7..ec382e60ef 100644 --- a/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb @@ -25,7 +25,7 @@ class Chef module ChefServer class DataBagsDir < RestListDir def make_child_entry(name, exists = false) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || DataBagDir.new(name, self, exists) end diff --git a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb index ebb274a9eb..4a4be19fe4 100644 --- a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb @@ -47,7 +47,7 @@ class Chef # } def make_child_entry(name, exists = nil) - @children.select { |child| child.name == name }.first if @children + @children.find { |child| child.name == name } if @children PolicyRevisionEntry.new(name, self, exists) end diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb index 488e9c0ed0..b5b602a208 100644 --- a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb @@ -168,7 +168,7 @@ class Chef end def make_child_entry(name, exists = nil) - @children.select { |child| child.name == name }.first if @children + @children.find { |child| child.name == name } if @children RestListEntry.new(name, self, exists) end end diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb index 9abafed5e7..172405763a 100644 --- a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb @@ -41,7 +41,7 @@ class Chef class VersionedCookbooksDir < CookbooksDir def make_child_entry(name) - result = @children.select { |child| child.name == name }.first if @children + result = @children.find { |child| child.name == name } if @children result || VersionedCookbookDir.new(name, self) end diff --git a/lib/chef/chef_fs/file_system/memory/memory_dir.rb b/lib/chef/chef_fs/file_system/memory/memory_dir.rb index beb661448d..6049f404b1 100644 --- a/lib/chef/chef_fs/file_system/memory/memory_dir.rb +++ b/lib/chef/chef_fs/file_system/memory/memory_dir.rb @@ -14,7 +14,7 @@ class Chef attr_reader :children def make_child_entry(name) - @children.select { |child| child.name == name }.first + @children.find { |child| child.name == name } end def add_child(child) diff --git a/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb b/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb index 6094fab493..84db2c2053 100644 --- a/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb +++ b/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb @@ -26,7 +26,7 @@ class Chef flatten(child, levels.nil? ? levels : levels - 1, &block) end else - block.call(value) + yield(value) end end end diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 9ebf705d79..d9078ac48c 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -493,7 +493,7 @@ class Chef if rendered_manifest.has_key?(segment) rendered_manifest[segment].each do |manifest_record| url_options = { :cookbook_name => name.to_s, :cookbook_version => version, :checksum => manifest_record["checksum"] } - manifest_record["url"] = url_generator.call(url_options) + manifest_record["url"] = yield(url_options) end end end diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb index b5e28cf54d..84065bf816 100644 --- a/lib/chef/http/authenticator.rb +++ b/lib/chef/http/authenticator.rb @@ -47,7 +47,7 @@ class Chef end def handle_request(method, url, headers = {}, data = false) - headers.merge!({ "X-Ops-Server-API-Version" => @api_version }) + headers["X-Ops-Server-API-Version"] = @api_version headers.merge!(authentication_headers(method, url, data, headers)) if sign_requests? [method, url, headers, data] end diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb index e0a02a05cf..58ae496418 100644 --- a/lib/chef/http/basic_client.rb +++ b/lib/chef/http/basic_client.rb @@ -104,7 +104,7 @@ class Chef # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy # here since we are really just trying to get the string built correctly. if String === proxy && !proxy.strip.empty? - if proxy.match(/^.*:\/\//) + if proxy =~ /^.*:\/\// proxy = URI.parse(proxy.strip) else proxy = URI.parse("#{url.scheme}://#{proxy.strip}") diff --git a/lib/chef/http/remote_request_id.rb b/lib/chef/http/remote_request_id.rb index ef8a18a1e3..a779df805e 100644 --- a/lib/chef/http/remote_request_id.rb +++ b/lib/chef/http/remote_request_id.rb @@ -25,7 +25,7 @@ class Chef end def handle_request(method, url, headers = {}, data = false) - headers.merge!({ "X-REMOTE-REQUEST-ID" => Chef::RequestID.instance.request_id }) + headers["X-REMOTE-REQUEST-ID"] = Chef::RequestID.instance.request_id [method, url, headers, data] end diff --git a/lib/chef/http/socketless_chef_zero_client.rb b/lib/chef/http/socketless_chef_zero_client.rb index c8590903f6..e25242c033 100644 --- a/lib/chef/http/socketless_chef_zero_client.rb +++ b/lib/chef/http/socketless_chef_zero_client.rb @@ -67,7 +67,7 @@ class Chef end if block_given? - block.call(@body) + yield(@body) else super end diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 657216bcf0..71127b5b57 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -514,7 +514,7 @@ class Chef output = edit_data(object, object_class: object_class) if Kernel.block_given? - output = block.call(output) + output = yield(output) else output.save end @@ -530,7 +530,7 @@ class Chef confirm("Do you really want to delete #{name}") if Kernel.block_given? - object = block.call + object = yield else object = klass.load(name) object.destroy diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index 2bdeea9781..21a251a011 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -102,7 +102,7 @@ class Chef end def specific_cookbook_version_url - "#{cookbooks_api_url}/#{@name_args[0]}/versions/#{@name_args[1].gsub('.', '_')}" + "#{cookbooks_api_url}/#{@name_args[0]}/versions/#{@name_args[1].tr('.', '_')}" end end end diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb index a6a4c82c85..c0280cb318 100644 --- a/lib/chef/knife/cookbook_site_show.rb +++ b/lib/chef/knife/cookbook_site_show.rb @@ -33,7 +33,7 @@ class Chef when 1 noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}") when 2 - noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}") + noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].tr('.', '_')}") end end diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index b05cae688c..5379b6504c 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -171,9 +171,10 @@ validation_client_name "#{@chef_config[:validation_client_name]}" def first_boot (@config[:first_boot_attributes] || {}).tap do |attributes| if @config[:policy_name] && @config[:policy_group] - attributes.merge!(:policy_name => @config[:policy_name], :policy_group => @config[:policy_group]) + attributes[:policy_name] = @config[:policy_name] + attributes[:policy_group] = @config[:policy_group] else - attributes.merge!(:run_list => @run_list) + attributes[:run_list] = @run_list end attributes.merge!(:tags => @config[:tags]) if @config[:tags] && !@config[:tags].empty? diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 95ab219c80..e636013c70 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -118,7 +118,7 @@ class Chef load_command(cmd_words) result = Chef::Knife.subcommands[find_longest_key(Chef::Knife.subcommands, cmd_words, "_")] - result || Chef::Knife.subcommands[args.first.gsub("-", "_")] + result || Chef::Knife.subcommands[args.first.tr("-", "_")] end def guess_category(args) diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 30a3db3cf2..520c9273af 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -177,7 +177,7 @@ class Chef # See lib/chef/search/query.rb for more examples of this. def create_result_filter(filter_string) final_filter = Hash.new - filter_string.gsub!(" ", "") + filter_string.delete!(" ") filters = filter_string.split(",") filters.each do |f| return_id, attr_path = f.split("=") diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 4184171a4e..9c0f8936f0 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -424,7 +424,7 @@ class Chef end.join(" \\; ") end - tmux_name = "'knife ssh #{@name_args[0].gsub(/:/, '=')}'" + tmux_name = "'knife ssh #{@name_args[0].tr(':', '=')}'" begin server = session.servers_for.first cmd = ["tmux new-session -d -s #{tmux_name}", diff --git a/lib/chef/log.rb b/lib/chef/log.rb index bfb5829be6..ac2baeb9d1 100644 --- a/lib/chef/log.rb +++ b/lib/chef/log.rb @@ -48,7 +48,7 @@ class Chef # Pick the first caller that is *not* part of the Chef gem, that's the # thing the user wrote. chef_gem_path = File.expand_path("../..", __FILE__) - caller(0..20).select { |c| !c.start_with?(chef_gem_path) }.first + caller(0..20).find { |c| !c.start_with?(chef_gem_path) } end def self.deprecation(msg = nil, location = caller(2..2)[0], &block) diff --git a/lib/chef/mixin/command.rb b/lib/chef/mixin/command.rb index 257ed11221..435daeda77 100644 --- a/lib/chef/mixin/command.rb +++ b/lib/chef/mixin/command.rb @@ -183,7 +183,7 @@ class Chef raise Chef::Exceptions::Exec, "#{dir} does not exist or is not a directory" end Dir.chdir(dir) do - block.call + yield end end diff --git a/lib/chef/mixin/properties.rb b/lib/chef/mixin/properties.rb index 2e33d2d0e7..1ee16b8b4a 100644 --- a/lib/chef/mixin/properties.rb +++ b/lib/chef/mixin/properties.rb @@ -98,7 +98,8 @@ class Chef options.each { |k, v| options[k.to_sym] = v if k.is_a?(String) } options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name) - options.merge!(name: name, declared_in: self) + options[:name] = name + options[:declared_in] = self if type == NOT_PASSED # If a type is not passed, the property derives from the diff --git a/lib/chef/mixin/why_run.rb b/lib/chef/mixin/why_run.rb index b2aa5949c0..69fee58e31 100644 --- a/lib/chef/mixin/why_run.rb +++ b/lib/chef/mixin/why_run.rb @@ -49,7 +49,7 @@ class Chef def add_action(descriptions, &block) @actions << [descriptions, block] if (@resource.respond_to?(:is_guard_interpreter) && @resource.is_guard_interpreter) || !Chef::Config[:why_run] - block.call + yield end events.resource_update_applied(@resource, @action, descriptions) end diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb index d184094bbb..83b5dd8c00 100644 --- a/lib/chef/provider/link.rb +++ b/lib/chef/provider/link.rb @@ -86,7 +86,7 @@ class Chef end def canonicalize(path) - Chef::Platform.windows? ? path.gsub("/", '\\') : path + Chef::Platform.windows? ? path.tr("/", '\\') : path end def action_create diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb index a514dcc66c..7127fa723f 100644 --- a/lib/chef/provider/package/portage.rb +++ b/lib/chef/provider/package/portage.rb @@ -66,7 +66,7 @@ class Chef txt.each_line do |line| if line =~ /\*\s+#{PACKAGE_NAME_PATTERN}/ - found_package_name = $&.gsub(/\*/, "").strip + found_package_name = $&.delete("*").strip if package =~ /\// #the category is specified if found_package_name == package availables[found_package_name] = nil diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb index 7a2db6b32b..6afe908180 100644 --- a/lib/chef/provider/package/rubygems.rb +++ b/lib/chef/provider/package/rubygems.rb @@ -410,7 +410,7 @@ class Chef def find_gem_by_path Chef::Log.debug("#{@new_resource} searching for 'gem' binary in path: #{ENV['PATH']}") separator = ::File::ALT_SEPARATOR ? ::File::ALT_SEPARATOR : ::File::SEPARATOR - path_to_first_gem = ENV["PATH"].split(::File::PATH_SEPARATOR).select { |path| ::File.exists?(path + separator + "gem") }.first + path_to_first_gem = ENV["PATH"].split(::File::PATH_SEPARATOR).find { |path| ::File.exists?(path + separator + "gem") } raise Chef::Exceptions::FileNotFound, "Unable to find 'gem' binary in path: #{ENV['PATH']}" if path_to_first_gem.nil? path_to_first_gem + separator + "gem" end diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb index 9c66fb4098..c0545e9fb3 100644 --- a/lib/chef/provider/service/arch.rb +++ b/lib/chef/provider/service/arch.rb @@ -33,7 +33,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init def load_current_resource raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exists?("/etc/rc.conf") - raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m) + raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless ::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m super @current_resource.enabled(daemons.include?(@current_resource.service_name)) @@ -49,7 +49,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init # ) def daemons entries = [] - if ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m) + if ::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m entries += $1.gsub(/\\?[\r\n]/, " ").gsub(/# *[^ ]+/, " ").split(" ") if $1.length > 0 end diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb index c31df25e68..c60bbf170c 100644 --- a/lib/chef/provider/service/openbsd.rb +++ b/lib/chef/provider/service/openbsd.rb @@ -92,7 +92,7 @@ class Chef old_services_list = rc_conf_local.match(/^pkg_scripts="(.*)"/) old_services_list = old_services_list ? old_services_list[1].split(" ") : [] new_services_list = old_services_list + [new_resource.service_name] - if rc_conf_local.match(/^pkg_scripts="(.*)"/) + if rc_conf_local =~ /^pkg_scripts="(.*)"/ new_rcl = rc_conf_local.sub(/^pkg_scripts="(.*)"/, "pkg_scripts=\"#{new_services_list.join(' ')}\"") else new_rcl = rc_conf_local + "\n" + "pkg_scripts=\"#{new_services_list.join(' ')}\"\n" @@ -159,7 +159,7 @@ class Chef result = false var_name = builtin_service_enable_variable_name if var_name - if rc_conf.match(/^#{Regexp.escape(var_name)}=(.*)/) + if rc_conf =~ /^#{Regexp.escape(var_name)}=(.*)/ result = true end end diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index edd41dba7e..3ac5ff51da 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -62,7 +62,7 @@ class Chef end platform, version = Chef::Platform.find_platform_and_version(run_context.node) - if platform == "ubuntu" && (8.04..9.04).include?(version.to_f) + if platform == "ubuntu" && (8.04..9.04).cover?(version.to_f) @upstart_job_dir = "/etc/event.d" @upstart_conf_suffix = "" else diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index 44143d583c..2d85b3897c 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -102,7 +102,7 @@ class Chef ) if ret.is_a? String - ret.gsub(/,/, " ").split(/ /) + ret.tr(",", " ").split(/ /) else ret end diff --git a/lib/chef/run_list.rb b/lib/chef/run_list.rb index b9ec9259ca..9647ef16e6 100644 --- a/lib/chef/run_list.rb +++ b/lib/chef/run_list.rb @@ -106,11 +106,11 @@ class Chef end def each(&block) - @run_list_items.each { |i| block.call(i) } + @run_list_items.each { |i| yield(i) } end def each_index(&block) - @run_list_items.each_index { |i| block.call(i) } + @run_list_items.each_index { |i| yield(i) } end def include?(item) diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb index 487a54f0df..ebf13bec36 100644 --- a/lib/chef/search/query.rb +++ b/lib/chef/search/query.rb @@ -87,7 +87,7 @@ WARNDEP response = call_rest_service(type, query: query, **args_h) if block - response["rows"].each { |row| block.call(row) if row } + response["rows"].each { |row| yield(row) if row } # # args_h[:rows] and args_h[:start] are the page size and # start position requested of the search index backing the diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index b0a779e44a..9bb615aee7 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -123,7 +123,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows user = get_info user[:last_logon] = user[:units_per_week] = 0 #ignored as per USER_INFO_3 doc user[:logon_hours] = nil #PBYTE field; \0 == no changes - proc.call(user) + yield(user) set_info(user) end diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 52ac4868c7..09501e66ce 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -550,7 +550,7 @@ BOOL WINAPI VerQueryValue( if handle == INVALID_HANDLE_VALUE Chef::ReservedNames::Win32::Error.raise! end - block.call(handle, find_data) + yield(handle, find_data) ensure FindClose(handle) if handle && handle != INVALID_HANDLE_VALUE end @@ -568,7 +568,7 @@ BOOL WINAPI VerQueryValue( if handle == INVALID_HANDLE_VALUE Chef::ReservedNames::Win32::Error.raise! end - block.call(handle) + yield(handle) ensure CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE end @@ -583,7 +583,7 @@ BOOL WINAPI VerQueryValue( if handle == INVALID_HANDLE_VALUE Chef::ReservedNames::Win32::Error.raise! end - block.call(handle) + yield(handle) ensure CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index 85a2744645..303fe1531d 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -41,7 +41,7 @@ class Chef private_class_method :get_system_metrics def self.method_name_from_marketing_name(marketing_name) - "#{marketing_name.gsub(/\s/, '_').gsub(/\./, '_').downcase}?" + "#{marketing_name.gsub(/\s/, '_').tr('.', '_').downcase}?" # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?" end |