diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-03-04 11:13:26 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-03-04 11:13:26 -0800 |
commit | 6ec521c0b86c266b9dd5d17a6060139dab404c3b (patch) | |
tree | a27bf7a007bfeebd64258c2e5652f6da37b73efc /lib/chef | |
parent | ee53ee1aba16ee2ad7c1fdde18869af971dcba67 (diff) | |
parent | 4fd88f1f3c7d847712e61abab2bac6cb4a987265 (diff) | |
download | chef-6ec521c0b86c266b9dd5d17a6060139dab404c3b.tar.gz |
Merge pull request #4617 from chef/lcg/chefstyle-perf
Autofixing new Perf cops in 0.37.2
Diffstat (limited to 'lib/chef')
54 files changed, 133 insertions, 83 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 8f30037ac7..e779a270aa 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -265,7 +265,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..04973b5135 100644 --- a/lib/chef/chef_fs/data_handler/container_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/container_data_handler.rb @@ -15,10 +15,16 @@ class Chef return key == "containername" end - def verify_integrity(object, entry, &on_error) + # Verify that the JSON hash for this type has a key that matches its name. + # + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object, entry) 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['containername']}')") 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..c6b6449d52 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 @@ -42,10 +42,16 @@ class Chef Chef::DataBagItem end - def verify_integrity(object, entry, &on_error) + # Verify that the JSON hash for this type has a key that matches its name. + # + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object, entry) 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..b30ae9c708 100644 --- a/lib/chef/chef_fs/data_handler/data_handler_base.rb +++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb @@ -185,14 +185,16 @@ class Chef result end - # # Verify that the JSON hash for this type has a key that matches its name. - # Calls the on_error block with the error, if there is one. # - def verify_integrity(object, entry, &on_error) + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object, entry) 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..0facd5d55d 100644 --- a/lib/chef/chef_fs/data_handler/organization_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/organization_data_handler.rb @@ -19,9 +19,15 @@ class Chef return key == "name" end - def verify_integrity(object, entry, &on_error) + # Verify that the JSON hash for this type has a key that matches its name. + # + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object, entry) 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..fa7bbe9101 100644 --- a/lib/chef/chef_fs/data_handler/policy_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/policy_data_handler.rb @@ -26,14 +26,20 @@ class Chef normalize_hash(policy, defaults) end - def verify_integrity(object_data, entry, &on_error) + # Verify that the JSON hash for this type has a key that matches its name. + # + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object_data, entry) 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 '#{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_id']}' doesn't match entry '#{revision}'.") 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..f7aa92373c 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 @@ -15,9 +15,15 @@ class Chef result end - def verify_integrity(object_data, entry, &on_error) + # Verify that the JSON hash for this type has a key that matches its name. + # + # @param object [Object] JSON hash of the object + # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying + # @yield [s] callback to handle errors + # @yieldparam [s<string>] error message + def verify_integrity(object_data, entry) 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 2857d8098e..906b94baad 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -489,7 +489,7 @@ class Chef # @deprecated This method was used by the Ruby Chef Server and is no longer # needed. There is no replacement. - def generate_manifest_with_urls(&url_generator) + def generate_manifest_with_urls Chef.log_deprecation("Deprecated method #generate_manifest_with_urls.") rendered_manifest = manifest.dup @@ -497,7 +497,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/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb index c21961479c..6df60aec89 100644 --- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb +++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb @@ -22,7 +22,7 @@ class Chef class GuardInterpreter class ResourceGuardInterpreter < DefaultGuardInterpreter - def initialize(parent_resource, command, opts, &block) + def initialize(parent_resource, command, opts) super(command, opts) @parent_resource = parent_resource @resource = get_interpreter_resource(parent_resource) diff --git a/lib/chef/http.rb b/lib/chef/http.rb index a3673ce281..dd02550294 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -159,7 +159,10 @@ class Chef # # If no block is given, the tempfile is returned, which means it's up to # you to unlink the tempfile when you're done with it. - def streaming_request(path, headers = {}, &block) + # + # @yield [tempfile] block to process the tempfile + # @yieldparams [tempfile<Tempfile>] tempfile + def streaming_request(path, headers = {}) url = create_url(path) response, rest_request, return_value = nil, nil, nil tempfile = nil 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..8c1578b976 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 @@ -148,7 +148,8 @@ class Chef @url.port end - def request(method, url, body, headers, &handler_block) + # FIXME: yard with @yield + def request(method, url, body, headers) request = req_to_rack(method, url, body, headers) res = ChefZero::SocketlessServerMap.request(port, request) diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 8f7232d927..636be0dbc7 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -515,11 +515,12 @@ class Chef response.body end - def create_object(object, pretty_name = nil, object_class: nil, &block) + # FIXME: yard with @yield + def create_object(object, pretty_name = nil, object_class: nil) output = edit_data(object, object_class: object_class) if Kernel.block_given? - output = block.call(output) + output = yield(output) else output.save end @@ -531,11 +532,12 @@ class Chef output(output) if config[:print_after] end - def delete_object(klass, name, delete_name = nil, &block) + # FIXME: yard with @yield + def delete_object(klass, name, delete_name = nil) 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 7ad70bc627..d96e07c03c 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -182,9 +182,10 @@ CONFIG 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 dc0b0cc39c..72329d8b95 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -124,7 +124,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..0cc3143ec7 100644 --- a/lib/chef/mixin/command.rb +++ b/lib/chef/mixin/command.rb @@ -177,13 +177,14 @@ class Chef # module_function :popen4 - def chdir_or_tmpdir(dir, &block) + # FIXME: yard with @yield + def chdir_or_tmpdir(dir) dir ||= Dir.tmpdir unless File.directory?(dir) 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/provides.rb b/lib/chef/mixin/provides.rb index 34a078c010..43a726de8c 100644 --- a/lib/chef/mixin/provides.rb +++ b/lib/chef/mixin/provides.rb @@ -7,12 +7,13 @@ class Chef # TODO no longer needed, remove or deprecate? include Chef::Mixin::DescendantsTracker - def provides(short_name, opts = {}, &block) + def provides(short_name, opts = {}) raise NotImplementedError, :provides end # Check whether this resource provides the resource_name DSL for the given # node. TODO remove this when we stop checking unregistered things. + # FIXME: yard with @yield def provides?(node, resource) raise NotImplementedError, :provides? end 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 6b01927d50..60abbed7c8 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/resource_collection/resource_list.rb b/lib/chef/resource_collection/resource_list.rb index 20bfc7b5f0..37eb12a107 100644 --- a/lib/chef/resource_collection/resource_list.rb +++ b/lib/chef/resource_collection/resource_list.rb @@ -76,7 +76,8 @@ class Chef @resources end - def execute_each_resource(&resource_exec_block) + # FIXME: yard with @yield + def execute_each_resource @iterator = ResourceCollection::StepableIterator.for_collection(@resources) @iterator.each_with_index do |resource, idx| @insert_after_idx = idx diff --git a/lib/chef/run_list.rb b/lib/chef/run_list.rb index b9ec9259ca..4dea938423 100644 --- a/lib/chef/run_list.rb +++ b/lib/chef/run_list.rb @@ -105,12 +105,14 @@ class Chef @run_list_items[pos] = parse_entry(item) end - def each(&block) - @run_list_items.each { |i| block.call(i) } + # FIXME: yard with @yield + def each + @run_list_items.each { |i| yield(i) } end - def each_index(&block) - @run_list_items.each_index { |i| block.call(i) } + # FIXME: yard with @yield + def each_index + @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/shell/model_wrapper.rb b/lib/chef/shell/model_wrapper.rb index 403f9479cf..8c3e456a9b 100644 --- a/lib/chef/shell/model_wrapper.rb +++ b/lib/chef/shell/model_wrapper.rb @@ -59,7 +59,8 @@ module Shell alias :load :show - def transform(what_to_transform, &block) + # FIXME: yard with @yield + def transform(what_to_transform) if what_to_transform == :all objects_to_transform = list_objects else diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index b0a779e44a..009252c4c1 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -119,11 +119,12 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows NetUser.net_local_group_add_member(nil, "Users", args[:name]) end - def user_modify(&proc) + # FIXME: yard with @yield + def user_modify 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..7489c94fd9 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -535,7 +535,8 @@ BOOL WINAPI VerQueryValue( # retrieves a file search handle and passes it # to +&block+ along with the find_data. also # ensures the handle is closed on exit of the block - def file_search_handle(path, &block) + # FIXME: yard with @yield + def file_search_handle(path) begin # Workaround for CHEF-4419: # Make sure paths starting with "/" has a drive letter @@ -550,7 +551,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 @@ -559,7 +560,8 @@ BOOL WINAPI VerQueryValue( # retrieves a file handle and passes it # to +&block+ along with the find_data. also # ensures the handle is closed on exit of the block - def file_handle(path, &block) + # FIXME: yard with @yield + def file_handle(path) begin path = canonical_encode_path(path) handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, @@ -568,13 +570,14 @@ 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 end - def symlink_file_handle(path, &block) + # FIXME: yard with @yield + def symlink_file_handle(path) begin path = encode_path(path) handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ, @@ -583,7 +586,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 |