summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb2
-rw-r--r--lib/chef/chef_fs/file_pattern.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/base_file.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/file_system_entry.rb2
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb2
-rw-r--r--lib/chef/cookbook/metadata.rb2
-rw-r--r--lib/chef/cookbook/synchronizer.rb2
-rw-r--r--lib/chef/cookbook_manifest.rb2
-rw-r--r--lib/chef/cookbook_uploader.rb2
-rw-r--r--lib/chef/http.rb2
-rw-r--r--lib/chef/http/socketless_chef_zero_client.rb4
-rw-r--r--lib/chef/knife.rb4
-rw-r--r--lib/chef/knife/cookbook_delete.rb2
-rw-r--r--lib/chef/knife/cookbook_upload.rb2
-rw-r--r--lib/chef/knife/core/gem_glob_loader.rb2
-rw-r--r--lib/chef/knife/core/generic_presenter.rb2
-rw-r--r--lib/chef/knife/list.rb10
-rw-r--r--lib/chef/knife/node_run_list_add.rb4
-rw-r--r--lib/chef/knife/node_run_list_remove.rb4
-rw-r--r--lib/chef/knife/node_run_list_set.rb4
-rw-r--r--lib/chef/knife/role_env_run_list_add.rb4
-rw-r--r--lib/chef/knife/role_env_run_list_set.rb4
-rw-r--r--lib/chef/knife/role_run_list_add.rb4
-rw-r--r--lib/chef/knife/role_run_list_set.rb4
-rw-r--r--lib/chef/knife/xargs.rb4
-rw-r--r--lib/chef/mixin/params_validate.rb4
-rw-r--r--lib/chef/mixin/properties.rb8
-rw-r--r--lib/chef/monkey_patches/net_http.rb2
-rw-r--r--lib/chef/node.rb2
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb2
-rw-r--r--lib/chef/provider.rb10
-rw-r--r--lib/chef/provider/package/apt.rb4
-rw-r--r--lib/chef/provider/service/freebsd.rb2
-rw-r--r--lib/chef/resource.rb14
-rw-r--r--lib/chef/resource/cab_package.rb2
-rw-r--r--lib/chef/resource/dmg_package.rb4
-rw-r--r--lib/chef/resource/msu_package.rb2
-rw-r--r--lib/chef/resource/windows_firewall_rule.rb4
-rw-r--r--lib/chef/role.rb4
-rw-r--r--lib/chef/run_context.rb2
-rw-r--r--lib/chef/run_context/cookbook_compiler.rb2
-rw-r--r--lib/chef/run_list.rb2
-rw-r--r--lib/chef/run_list/run_list_expansion.rb2
-rw-r--r--lib/chef/run_status.rb2
-rw-r--r--lib/chef/runner.rb4
-rw-r--r--lib/chef/util/diff.rb4
-rw-r--r--lib/chef/util/dsc/configuration_generator.rb4
-rw-r--r--lib/chef/util/threaded_job_queue.rb2
-rw-r--r--lib/chef/win32/security/acl.rb2
-rw-r--r--lib/chef/win32/version.rb2
55 files changed, 86 insertions, 94 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index d8bb3bb7ed..807d5e0155 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -531,7 +531,7 @@ class Chef
# /cookbooks/name-version -> /cookbooks/name
entry.children.map { |child| split_name_version(child.name)[0] }.uniq
else
- entry.children.map { |child| child.name }
+ entry.children.map(&:name)
end
rescue Chef::ChefFS::FileSystem::NotFoundError
# If the cookbooks dir doesn't exist, we have no cookbooks (not 404)
diff --git a/lib/chef/chef_fs/file_pattern.rb b/lib/chef/chef_fs/file_pattern.rb
index 48e28ccc39..f4889fbd86 100644
--- a/lib/chef/chef_fs/file_pattern.rb
+++ b/lib/chef/chef_fs/file_pattern.rb
@@ -126,7 +126,7 @@ class Chef
# abc/*def.exact_path == 'abc/def'
# abc/x\\yz.exact_path == 'abc/xyz'
def exact_path
- return nil if has_double_star || exact_parts.any? { |part| part.nil? }
+ return nil if has_double_star || exact_parts.any?(&:nil?)
result = Chef::ChefFS::PathUtils.join(*exact_parts)
is_absolute ? Chef::ChefFS::PathUtils.join("", result) : result
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 d1d92f508e..20a6895116 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
@@ -186,7 +186,7 @@ class Chef
RestListDir.new("users", self, nil, Chef::ChefFS::DataHandler::UserDataHandler.new),
]
end
- result.sort_by { |child| child.name }
+ result.sort_by(&:name)
end
end
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 73f3d4f4e6..15729b7206 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
@@ -94,7 +94,7 @@ class Chef
container.add_child(CookbookFile.new(parts[parts.length - 1], container, file))
end
end
- @children = @children.sort_by { |c| c.name }
+ @children = @children.sort_by(&:name)
end
@children
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
index 8bdaf75a30..2dae242223 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
@@ -38,7 +38,7 @@ class Chef
def read
tmpfile = rest.streaming_request(file[:url])
- File.open(tmpfile, "rb") { |f| f.read }
+ File.open(tmpfile, "rb", &:read)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading #{file[:url]}: #{e}")
rescue Net::HTTPClientException => e
diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb
index b36a1ae214..daefc3a8b1 100644
--- a/lib/chef/chef_fs/file_system/repository/base_file.rb
+++ b/lib/chef/chef_fs/file_system/repository/base_file.rb
@@ -122,7 +122,7 @@ class Chef
if is_ruby_file?
data_handler.from_ruby(file_path).to_json
else
- File.open(file_path, "rb") { |f| f.read }
+ File.open(file_path, "rb", &:read)
end
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
index 31ccf1b24f..1708428372 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
@@ -140,7 +140,7 @@ class Chef
end
def read
- File.open(file_path, "rb") { |f| f.read }
+ File.open(file_path, "rb", &:read)
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
index 31a8a2da80..de1f071fb3 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
@@ -90,7 +90,7 @@ class Chef
@children ||= begin
result = child_paths.keys.sort.map { |name| make_child_entry(name) }
result += CHILDREN.map { |name| make_child_entry(name) }
- result.select { |c| c && c.exists? }.sort_by { |c| c.name }
+ result.select { |c| c && c.exists? }.sort_by(&:name)
end
end
diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
index 6cb77a15a4..7c2d3e1522 100644
--- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
+++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
@@ -126,7 +126,7 @@ class Chef
end
def read
- File.open(file_path, "rb") { |f| f.read }
+ File.open(file_path, "rb", &:read)
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index ecdfa7ba57..767196ea0e 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -185,7 +185,7 @@ class Chef
end
def empty?
- cookbook_settings.values.all? { |files_hash| files_hash.empty? } && metadata_filenames.size == 0
+ cookbook_settings.values.all?(&:empty?) && metadata_filenames.size == 0
end
def chefignore
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 8b4af310ed..d5821a799e 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -606,7 +606,7 @@ class Chef
specify more than one version constraint for a particular cookbook.
Consult https://docs.chef.io/config_rb_metadata.html for the updated syntax.
- Called by: #{caller_name} '#{dep_name}', #{version_constraints.map { |vc| vc.inspect }.join(", ")}
+ Called by: #{caller_name} '#{dep_name}', #{version_constraints.map(&:inspect).join(", ")}
Called from:
#{caller[0...5].map { |line| " " + line }.join("\n")}
OBSOLETED
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index 62cc39d483..b6bcd2c150 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -138,7 +138,7 @@ class Chef
end
def files_by_cookbook
- files.group_by { |file| file.cookbook }
+ files.group_by(&:cookbook)
end
def files_remaining_by_cookbook
diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb
index 34ece80e19..b16eeccbca 100644
--- a/lib/chef/cookbook_manifest.rb
+++ b/lib/chef/cookbook_manifest.rb
@@ -180,7 +180,7 @@ class Chef
end
def each_file(excluded_parts: [], &block)
- excluded_parts = Array(excluded_parts).map { |p| p.to_s }
+ excluded_parts = Array(excluded_parts).map(&:to_s)
manifest[:all_files].each do |file|
seg = file[:name].split("/")[0]
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index 479a26a3f0..31fec8cfd1 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -120,7 +120,7 @@ class Chef
# but we need the base64 encoding for the content-md5
# header
checksum64 = Base64.encode64([checksum].pack("H*")).strip
- file_contents = File.open(file, "rb") { |f| f.read }
+ file_contents = File.open(file, "rb", &:read)
# Custom headers. 'content-type' disables JSON serialization of the request body.
headers = { "content-type" => "application/x-binary", "content-md5" => checksum64, "accept" => "application/json" }
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 3239aac442..5546156031 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -372,7 +372,7 @@ class Chef
if block_given?
request, response = client.request(method, url, body, headers, &response_handler)
else
- request, response = client.request(method, url, body, headers) { |r| r.read_body }
+ request, response = client.request(method, url, body, headers, &:read_body)
return_value = response.read_body
end
@last_response = response
diff --git a/lib/chef/http/socketless_chef_zero_client.rb b/lib/chef/http/socketless_chef_zero_client.rb
index 95f511a4d3..b83fdbd41b 100644
--- a/lib/chef/http/socketless_chef_zero_client.rb
+++ b/lib/chef/http/socketless_chef_zero_client.rb
@@ -134,7 +134,7 @@ class Chef
511 => "Network Authentication Required",
}.freeze
- STATUS_MESSAGE.each_value { |v| v.freeze }
+ STATUS_MESSAGE.each_value(&:freeze)
STATUS_MESSAGE.freeze
def initialize(base_url)
@@ -201,7 +201,7 @@ class Chef
def headers_extracted_from_options
options.reject { |name, _| KNOWN_OPTIONS.include?(name) }.map do |name, value|
- [name.to_s.split("_").map { |segment| segment.capitalize }.join("-"), value]
+ [name.to_s.split("_").map(&:capitalize).join("-"), value]
end
end
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index 0617c79e8e..28634d9e44 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -231,9 +231,7 @@ class Chef
end
def self.load_deps
- dependency_loaders.each do |dep_loader|
- dep_loader.call
- end
+ dependency_loaders.each(&:call)
end
OFFICIAL_PLUGINS = %w{ec2 rackspace windows openstack azure google linode push vcenter lpar}.freeze
diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb
index 381df56d71..98e54f486d 100644
--- a/lib/chef/knife/cookbook_delete.rb
+++ b/lib/chef/knife/cookbook_delete.rb
@@ -106,7 +106,7 @@ class Chef
end
valid_responses[(available_versions.size + 1).to_s] = :all
question << "#{available_versions.size + 1}. All versions\n\n"
- responses = ask_question(question).split(",").map { |response| response.strip }
+ responses = ask_question(question).split(",").map(&:strip)
if responses.empty?
ui.error("No versions specified, exiting")
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index ef66cc16c7..d73fa9ae68 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -92,7 +92,7 @@ class Chef
# Get a list of cookbooks and their versions from the server
# to check for the existence of a cookbook's dependencies.
@server_side_cookbooks = Chef::CookbookVersion.list_all_versions
- justify_width = @server_side_cookbooks.map { |name| name.size }.max.to_i + 2
+ justify_width = @server_side_cookbooks.map(&:size).max.to_i + 2
if config[:all]
cookbook_repo.load_cookbooks
cookbooks_for_upload = []
diff --git a/lib/chef/knife/core/gem_glob_loader.rb b/lib/chef/knife/core/gem_glob_loader.rb
index 6b969c695f..8fe228b848 100644
--- a/lib/chef/knife/core/gem_glob_loader.rb
+++ b/lib/chef/knife/core/gem_glob_loader.rb
@@ -118,7 +118,7 @@ class Chef
glob = File.join(Chef::Util::PathHelper.escape_glob_dir(spec.full_gem_path, dirs), glob)
- Dir[glob].map { |f| f.untaint }
+ Dir[glob].map(&:untaint)
end
def from_different_chef_version?(path)
diff --git a/lib/chef/knife/core/generic_presenter.rb b/lib/chef/knife/core/generic_presenter.rb
index fe8a84b753..90f529a3d9 100644
--- a/lib/chef/knife/core/generic_presenter.rb
+++ b/lib/chef/knife/core/generic_presenter.rb
@@ -218,7 +218,7 @@ class Chef
collected[cookbook] = versions["versions"].map { |v| v["version"] }
collected
end
- key_length = versions_by_cookbook.empty? ? 0 : versions_by_cookbook.keys.map { |name| name.size }.max + 2
+ key_length = versions_by_cookbook.empty? ? 0 : versions_by_cookbook.keys.map(&:size).max + 2
versions_by_cookbook.sort.map do |cookbook, versions|
"#{cookbook.ljust(key_length)} #{versions.join(" ")}"
end
diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb
index 08bb73e489..e5e196ecea 100644
--- a/lib/chef/knife/list.rb
+++ b/lib/chef/knife/list.rb
@@ -77,7 +77,7 @@ class Chef
# Process directories
if !config[:bare_directories]
- dir_results = parallelize(all_results.select { |result| result.dir? }) do |result|
+ dir_results = parallelize(all_results.select(&:dir?)) do |result|
add_dir_result(result)
end.flatten(1)
@@ -97,7 +97,7 @@ class Chef
end
# Sort by path for happy output
- results = results.sort_by { |result| result.path }
+ results = results.sort_by(&:path)
dir_results = dir_results.sort_by { |result| result[0].path }
# Print!
@@ -123,7 +123,7 @@ class Chef
def add_dir_result(result)
begin
- children = result.children.sort_by { |child| child.name }
+ children = result.children.sort_by(&:name)
rescue Chef::ChefFS::FileSystem::NotFoundError => e
ui.error "#{format_path(e.entry)}: No such file or directory"
return []
@@ -131,7 +131,7 @@ class Chef
result = [ [ result, children ] ]
if config[:recursive]
- child_dirs = children.select { |child| child.dir? }
+ child_dirs = children.select(&:dir?)
result += parallelize(child_dirs) { |child| add_dir_result(child) }.flatten(1).to_a
end
result
@@ -144,7 +144,7 @@ class Chef
def print_results(results, indent)
return if results.length == 0
- print_space = results.map { |result| result.length }.max + 2
+ print_space = results.map(&:length).max + 2
if config[:one_column] || !stdout.isatty
columns = 0
else
diff --git a/lib/chef/knife/node_run_list_add.rb b/lib/chef/knife/node_run_list_add.rb
index b8d7dc0b99..9b50e2483a 100644
--- a/lib/chef/knife/node_run_list_add.rb
+++ b/lib/chef/knife/node_run_list_add.rb
@@ -44,11 +44,11 @@ class Chef
if @name_args.size > 2
# Check for nested lists and create a single plain one
entries = @name_args[1..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[1].split(",").map { |e| e.strip }
+ entries = @name_args[1].split(",").map(&:strip)
end
if config[:after] && config[:before]
diff --git a/lib/chef/knife/node_run_list_remove.rb b/lib/chef/knife/node_run_list_remove.rb
index 2c8aa78929..36c98a724b 100644
--- a/lib/chef/knife/node_run_list_remove.rb
+++ b/lib/chef/knife/node_run_list_remove.rb
@@ -35,11 +35,11 @@ class Chef
if @name_args.size > 2
# Check for nested lists and create a single plain one
entries = @name_args[1..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[1].split(",").map { |e| e.strip }
+ entries = @name_args[1].split(",").map(&:strip)
end
# iterate over the list of things to remove,
diff --git a/lib/chef/knife/node_run_list_set.rb b/lib/chef/knife/node_run_list_set.rb
index c2dd987864..eae05003ff 100644
--- a/lib/chef/knife/node_run_list_set.rb
+++ b/lib/chef/knife/node_run_list_set.rb
@@ -37,11 +37,11 @@ class Chef
elsif @name_args.size > 2
# Check for nested lists and create a single plain one
entries = @name_args[1..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[1].split(",").map { |e| e.strip }
+ entries = @name_args[1].split(",").map(&:strip)
end
node = Chef::Node.load(@name_args[0])
diff --git a/lib/chef/knife/role_env_run_list_add.rb b/lib/chef/knife/role_env_run_list_add.rb
index 997fccff42..8f6a5cadba 100644
--- a/lib/chef/knife/role_env_run_list_add.rb
+++ b/lib/chef/knife/role_env_run_list_add.rb
@@ -69,11 +69,11 @@ class Chef
if @name_args.size > 2
# Check for nested lists and create a single plain one
entries = @name_args[2..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[2].split(",").map { |e| e.strip }
+ entries = @name_args[2].split(",").map(&:strip)
end
add_to_env_run_list(role, environment, entries, config[:after])
diff --git a/lib/chef/knife/role_env_run_list_set.rb b/lib/chef/knife/role_env_run_list_set.rb
index 4f79d50cc2..084bc02aff 100644
--- a/lib/chef/knife/role_env_run_list_set.rb
+++ b/lib/chef/knife/role_env_run_list_set.rb
@@ -52,11 +52,11 @@ class Chef
elsif @name_args.size > 2
# Check for nested lists and create a single plain one
entries = @name_args[2..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[2].split(",").map { |e| e.strip }
+ entries = @name_args[2].split(",").map(&:strip)
end
set_env_run_list(role, environment, entries )
diff --git a/lib/chef/knife/role_run_list_add.rb b/lib/chef/knife/role_run_list_add.rb
index ff0addbcfe..3c4961cbe1 100644
--- a/lib/chef/knife/role_run_list_add.rb
+++ b/lib/chef/knife/role_run_list_add.rb
@@ -69,11 +69,11 @@ class Chef
if @name_args.size > 1
# Check for nested lists and create a single plain one
entries = @name_args[1..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[1].split(",").map { |e| e.strip }
+ entries = @name_args[1].split(",").map(&:strip)
end
add_to_env_run_list(role, environment, entries, config[:after])
diff --git a/lib/chef/knife/role_run_list_set.rb b/lib/chef/knife/role_run_list_set.rb
index 447ce145b8..7302797c33 100644
--- a/lib/chef/knife/role_run_list_set.rb
+++ b/lib/chef/knife/role_run_list_set.rb
@@ -51,11 +51,11 @@ class Chef
elsif @name_args.size > 1
# Check for nested lists and create a single plain one
entries = @name_args[1..-1].map do |entry|
- entry.split(",").map { |e| e.strip }
+ entry.split(",").map(&:strip)
end.flatten
else
# Convert to array and remove the extra spaces
- entries = @name_args[1].split(",").map { |e| e.strip }
+ entries = @name_args[1].split(",").map(&:strip)
end
set_env_run_list(role, environment, entries )
diff --git a/lib/chef/knife/xargs.rb b/lib/chef/knife/xargs.rb
index a8ec99920b..13135ba47c 100644
--- a/lib/chef/knife/xargs.rb
+++ b/lib/chef/knife/xargs.rb
@@ -183,7 +183,7 @@ class Chef
end
# Create the command
- paths = tempfiles.keys.map { |tempfile| tempfile.path }.join(" ")
+ paths = tempfiles.keys.map(&:path).join(" ")
if config[:replace_all]
final_command = command.gsub(config[:replace_all], paths)
elsif config[:replace_first]
@@ -197,7 +197,7 @@ class Chef
def destroy_tempfiles(tempfiles)
# Unlink the files now that we're done with them
- tempfiles.each_key { |tempfile| tempfile.close! }
+ tempfiles.each_key(&:close!)
end
def xargs_files(command, tempfiles)
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index ba280f9eb9..0bf3543fbf 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -177,7 +177,7 @@ class Chef
end
# Ruby will print :something as something, which confuses users so make sure to print them as symbols
# by inspecting the value instead of just printing it
- raise Exceptions::ValidationFailed, _validation_message(key, "Option #{key} must be equal to one of: #{to_be.map { |v| v.inspect }.join(", ")}! You passed #{value.inspect}.")
+ raise Exceptions::ValidationFailed, _validation_message(key, "Option #{key} must be equal to one of: #{to_be.map(&:inspect).join(", ")}! You passed #{value.inspect}.")
end
end
@@ -438,7 +438,7 @@ class Chef
if passed
true
else
- message = "Property #{key} must be one of: #{to_be.map { |v| v.inspect }.join(", ")}! You passed #{value.inspect}."
+ message = "Property #{key} must be one of: #{to_be.map(&:inspect).join(", ")}! You passed #{value.inspect}."
unless errors.empty?
message << " Errors:\n#{errors.map { |m| "- #{m}" }.join("\n")}"
end
diff --git a/lib/chef/mixin/properties.rb b/lib/chef/mixin/properties.rb
index dcae012a23..ecb589e015 100644
--- a/lib/chef/mixin/properties.rb
+++ b/lib/chef/mixin/properties.rb
@@ -192,7 +192,7 @@ class Chef
#
def state_properties(*names)
unless names.empty?
- names = names.map { |name| name.to_sym }.uniq
+ names = names.map(&:to_sym).uniq
local_properties = properties(false)
# Add new properties to the list.
@@ -214,7 +214,7 @@ class Chef
end
end
- properties.values.select { |property| property.desired_state? }
+ properties.values.select(&:desired_state?)
end
#
@@ -241,7 +241,7 @@ class Chef
#
def identity_properties(*names)
unless names.empty?
- names = names.map { |name| name.to_sym }
+ names = names.map(&:to_sym)
# Add or change properties that are not part of the identity.
names.each do |name|
@@ -263,7 +263,7 @@ class Chef
end
end
- result = properties.values.select { |property| property.identity? }
+ result = properties.values.select(&:identity?)
result = [ properties[:name] ] if result.empty?
result
end
diff --git a/lib/chef/monkey_patches/net_http.rb b/lib/chef/monkey_patches/net_http.rb
index e1a65a369c..a50b7fd74c 100644
--- a/lib/chef/monkey_patches/net_http.rb
+++ b/lib/chef/monkey_patches/net_http.rb
@@ -25,7 +25,7 @@ module Net
end
end
-if Net::HTTP.instance_methods.map { |m| m.to_s }.include?("proxy_uri")
+if Net::HTTP.instance_methods.map(&:to_s).include?("proxy_uri")
begin
# Ruby 2.0 changes the way proxy support is implemented in Net::HTTP.
# The implementation does not work correctly with IPv6 literals because it
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 1701f00c0f..6d5bb6d8e4 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -523,7 +523,7 @@ class Chef
"default" => attributes.combined_default.to_hash,
"override" => attributes.combined_override.to_hash,
# Render correctly for run_list items so malformed json does not result
- "run_list" => @primary_runlist.run_list.map { |item| item.to_s },
+ "run_list" => @primary_runlist.run_list.map(&:to_s),
}
# Chef Server rejects node JSON with extra keys; prior to 12.3,
# "policy_name" and "policy_group" are unknown; after 12.3 they are
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 706efd2e0b..4afb4d7d60 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -235,7 +235,7 @@ class Chef
def runlist_override_sanity_check!
# Convert to array and remove whitespace
if override_runlist.is_a?(String)
- @override_runlist = override_runlist.split(",").map { |e| e.strip }
+ @override_runlist = override_runlist.split(",").map(&:strip)
end
@override_runlist = [override_runlist].flatten.compact
override_runlist.map! do |item|
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 97e3a310e5..6d1985bbbb 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -242,7 +242,7 @@ class Chef
Chef::Runner.new(run_context).converge
return_value
ensure
- if run_context.resource_collection.any? { |r| r.updated? }
+ if run_context.resource_collection.any?(&:updated?)
new_resource.updated_by_last_action(true)
end
@run_context = old_run_context
@@ -270,8 +270,8 @@ class Chef
raise ArgumentError, "converge_if_changed must be passed a block!"
end
- properties = new_resource.class.state_properties.map { |p| p.name } if properties.empty?
- properties = properties.map { |p| p.to_sym }
+ properties = new_resource.class.state_properties.map(&:name) if properties.empty?
+ properties = properties.map(&:to_sym)
if current_resource
# Collect the list of modified properties
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
@@ -293,7 +293,7 @@ class Chef
end
# Print the pretty green text and run the block
- property_size = modified.map { |p| p.size }.max
+ property_size = modified.map(&:size).max
modified.map! do |p|
properties_str = if new_resource.sensitive || new_resource.class.properties[p].sensitive?
"(suppressed sensitive property)"
@@ -307,7 +307,7 @@ class Chef
else
# The resource doesn't exist. Mark that we are *creating* this, and
# write down any properties we are setting.
- property_size = properties.map { |p| p.size }.max
+ property_size = properties.map(&:size).max
created = properties.map do |property|
default = " (default value)" unless new_resource.property_is_set?(property)
properties_str = if new_resource.sensitive || new_resource.class.properties[property].sensitive?
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
index b8f2356811..744e5b2e83 100644
--- a/lib/chef/provider/package/apt.rb
+++ b/lib/chef/provider/package/apt.rb
@@ -84,9 +84,7 @@ class Chef
@locked_packages ||=
begin
locked = shell_out!("apt-mark", "showhold")
- locked.stdout.each_line.map do |line|
- line.strip
- end
+ locked.stdout.each_line.map(&:strip)
end
end
diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb
index ee0cad53f3..7733831945 100644
--- a/lib/chef/provider/service/freebsd.rb
+++ b/lib/chef/provider/service/freebsd.rb
@@ -118,7 +118,7 @@ class Chef
private
def read_rc_conf
- ::File.open("/etc/rc.conf", "r") { |file| file.readlines }
+ ::File.open("/etc/rc.conf", "r", &:readlines)
end
def write_rc_conf(lines)
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 93384e456a..7f0895d6c9 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -644,7 +644,7 @@ class Chef
end
end
- ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
+ ivars = instance_variables.map(&:to_sym) - HIDDEN_IVARS
ivars.each do |ivar|
iv = ivar.to_s.sub(/^@/, "")
if all_props.keys.include?(iv)
@@ -665,7 +665,7 @@ class Chef
end
def inspect
- ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
+ ivars = instance_variables.map(&:to_sym) - FORBIDDEN_IVARS
ivars.inject("<#{self}") do |str, ivar|
str << " #{ivar}: #{instance_variable_get(ivar).inspect}"
end << ">"
@@ -675,7 +675,7 @@ class Chef
# is loaded. activesupport will call as_json and skip over to_json. This ensure
# json is encoded as expected
def as_json(*a)
- safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
+ safe_ivars = instance_variables.map(&:to_sym) - FORBIDDEN_IVARS
instance_vars = {}
safe_ivars.each do |iv|
instance_vars[iv.to_s.sub(/^@/, "")] = instance_variable_get(iv)
@@ -698,7 +698,7 @@ class Chef
self.class.state_properties.each do |p|
result[p.name] = p.get(self)
end
- safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
+ safe_ivars = instance_variables.map(&:to_sym) - FORBIDDEN_IVARS
safe_ivars.each do |iv|
key = iv.to_s.sub(/^@/, "").to_sym
next if result.key?(key)
@@ -783,7 +783,7 @@ class Chef
# @return [Array<Symbol>] All property names with desired state.
#
def self.state_attrs(*names)
- state_properties(*names).map { |property| property.name }
+ state_properties(*names).map(&:name)
end
#
@@ -813,7 +813,7 @@ class Chef
def self.identity_property(name = nil)
result = identity_properties(*Array(name))
if result.size > 1
- raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map { |r| r.name }.join(", ")})."
+ raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map(&:name).join(", ")})."
end
result.first
@@ -1296,7 +1296,7 @@ class Chef
# life as well.
@@sorted_descendants = nil
def self.sorted_descendants
- @@sorted_descendants ||= descendants.sort_by { |x| x.to_s }
+ @@sorted_descendants ||= descendants.sort_by(&:to_s)
end
def self.inherited(child)
diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb
index 04d6f97976..82f8fd90ea 100644
--- a/lib/chef/resource/cab_package.rb
+++ b/lib/chef/resource/cab_package.rb
@@ -39,7 +39,7 @@ class Chef
uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false)
end
end),
- default: lazy { |r| r.package_name }, default_description: "The package name."
+ default: lazy(&:package_name), default_description: "The package name."
end
end
end
diff --git a/lib/chef/resource/dmg_package.rb b/lib/chef/resource/dmg_package.rb
index dfe6eb45c6..3972b7abb9 100644
--- a/lib/chef/resource/dmg_package.rb
+++ b/lib/chef/resource/dmg_package.rb
@@ -48,12 +48,12 @@ class Chef
property :volumes_dir, String,
description: "The directory under /Volumes where the dmg is mounted if it differs from the name of the .dmg file.",
- default: lazy { |r| r.app }, default_description: "The value passed for the application name."
+ default: lazy(&:app), default_description: "The value passed for the application name."
property :dmg_name, String,
description: "The name of the .dmg file if it differs from that of the app, or if the name has spaces.",
desired_state: false,
- default: lazy { |r| r.app }, default_description: "The value passed for the application name."
+ default: lazy(&:app), default_description: "The value passed for the application name."
property :type, String,
description: "The type of package.",
diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb
index 75515b4f78..270cbd4b16 100644
--- a/lib/chef/resource/msu_package.rb
+++ b/lib/chef/resource/msu_package.rb
@@ -40,7 +40,7 @@ class Chef
uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false)
end
end),
- default: lazy { |r| r.package_name }
+ default: lazy(&:package_name)
property :checksum, String, desired_state: false,
description: "SHA-256 digest used to verify the checksum of the downloaded MSU package."
diff --git a/lib/chef/resource/windows_firewall_rule.rb b/lib/chef/resource/windows_firewall_rule.rb
index 0787d634f4..424d8d0fde 100644
--- a/lib/chef/resource/windows_firewall_rule.rb
+++ b/lib/chef/resource/windows_firewall_rule.rb
@@ -42,7 +42,7 @@ class Chef
property :local_port, [String, Integer, Array],
# split various formats of comma separated lists and provide a sorted array of strings to match PS output
- coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map { |x| x.to_s } },
+ coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map(&:to_s) },
description: "The local port the firewall rule applies to."
property :remote_address, String,
@@ -50,7 +50,7 @@ class Chef
property :remote_port, [String, Integer, Array],
# split various formats of comma separated lists and provide a sorted array of strings to match PS output
- coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map { |x| x.to_s } },
+ coerce: proc { |d| d.is_a?(String) ? d.split(/\s*,\s*/).sort : Array(d).sort.map(&:to_s) },
description: "The remote port the firewall rule applies to."
property :direction, [Symbol, String],
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index 8607833a55..d32de42756 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -143,9 +143,9 @@ class Chef
# Render to_json correctly for run_list items (both run_list and evn_run_lists)
# so malformed json does not result
- "run_list" => run_list.run_list.map { |item| item.to_s },
+ "run_list" => run_list.run_list.map(&:to_s),
"env_run_lists" => env_run_lists_without_default.inject({}) do |accumulator, (k, v)|
- accumulator[k] = v.map { |x| x.to_s }
+ accumulator[k] = v.map(&:to_s)
accumulator
end,
}
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index e0a3698e1b..eb211dc5a5 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -705,7 +705,7 @@ class Chef
resource_collection=
runner
runner=
- }.map { |x| x.to_sym }
+ }.map(&:to_sym)
# Verify that we didn't miss any methods
unless @__skip_method_checking # hook specifically for compat_resource
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb
index 0af7783eb7..116020de19 100644
--- a/lib/chef/run_context/cookbook_compiler.rb
+++ b/lib/chef/run_context/cookbook_compiler.rb
@@ -331,7 +331,7 @@ class Chef
# +cookbook_name+ in lexical sort order.
def each_cookbook_dep(cookbook_name, &block)
cookbook = cookbook_collection[cookbook_name]
- cookbook.metadata.dependencies.keys.sort.map { |x| x.to_sym }.each(&block)
+ cookbook.metadata.dependencies.keys.sort.map(&:to_sym).each(&block)
end
# Given a +recipe_name+, finds the file associated with the recipe.
diff --git a/lib/chef/run_list.rb b/lib/chef/run_list.rb
index e04e763fe6..1108b5d2c1 100644
--- a/lib/chef/run_list.rb
+++ b/lib/chef/run_list.rb
@@ -87,7 +87,7 @@ class Chef
end
def for_json
- to_a.map { |item| item.to_s }
+ to_a.map(&:to_s)
end
def to_json(*a)
diff --git a/lib/chef/run_list/run_list_expansion.rb b/lib/chef/run_list/run_list_expansion.rb
index 99fcdcfd58..9cd7aa1394 100644
--- a/lib/chef/run_list/run_list_expansion.rb
+++ b/lib/chef/run_list/run_list_expansion.rb
@@ -141,7 +141,7 @@ class Chef
end
def errors
- @missing_roles_with_including_role.map { |item| item.first }
+ @missing_roles_with_including_role.map(&:first)
end
def to_json(*a)
diff --git a/lib/chef/run_status.rb b/lib/chef/run_status.rb
index 575d31159b..4d3eae21ae 100644
--- a/lib/chef/run_status.rb
+++ b/lib/chef/run_status.rb
@@ -75,7 +75,7 @@ class Chef::RunStatus
# The list of all resources in the current run context's +resource_collection+
# that are marked as updated
def updated_resources
- @run_context && @run_context.resource_collection.select { |r| r.updated }
+ @run_context && @run_context.resource_collection.select(&:updated)
end
# The backtrace from +exception+, if any
diff --git a/lib/chef/runner.rb b/lib/chef/runner.rb
index c1d4a9b3a9..a0ae61fe4c 100644
--- a/lib/chef/runner.rb
+++ b/lib/chef/runner.rb
@@ -89,9 +89,7 @@ class Chef
# +run_action+ for each resource in turn.
def converge
# Resolve all lazy/forward references in notifications
- run_context.resource_collection.each do |resource|
- resource.resolve_notification_references
- end
+ run_context.resource_collection.each(&:resolve_notification_references)
# Execute each resource.
run_context.resource_collection.execute_each_resource do |resource|
diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb
index 64cf41fab2..326f67a38e 100644
--- a/lib/chef/util/diff.rb
+++ b/lib/chef/util/diff.rb
@@ -90,8 +90,8 @@ class Chef
diff_str = ""
file_length_difference = 0
- old_data = IO.readlines(old_file).map { |e| e.chomp }
- new_data = IO.readlines(new_file).map { |e| e.chomp }
+ old_data = IO.readlines(old_file).map(&:chomp)
+ new_data = IO.readlines(new_file).map(&:chomp)
diff_data = ::Diff::LCS.diff(old_data, new_data)
return diff_str if old_data.empty? && new_data.empty?
diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb
index d2d358d61f..0c101b204d 100644
--- a/lib/chef/util/dsc/configuration_generator.rb
+++ b/lib/chef/util/dsc/configuration_generator.rb
@@ -132,9 +132,7 @@ class Chef::Util::DSC
end
def get_configuration_document(document_path)
- ::File.open(document_path, "rb") do |file|
- file.read
- end
+ ::File.open(document_path, "rb", &:read)
end
end
end
diff --git a/lib/chef/util/threaded_job_queue.rb b/lib/chef/util/threaded_job_queue.rb
index eaffd9ea70..6b13bf99a3 100644
--- a/lib/chef/util/threaded_job_queue.rb
+++ b/lib/chef/util/threaded_job_queue.rb
@@ -54,7 +54,7 @@ class Chef
end
end
workers.each { |worker| self << Thread.method(:exit) }
- workers.each { |worker| worker.join }
+ workers.each(&:join)
end
end
end
diff --git a/lib/chef/win32/security/acl.rb b/lib/chef/win32/security/acl.rb
index 548194fb7d..ec963fb522 100644
--- a/lib/chef/win32/security/acl.rb
+++ b/lib/chef/win32/security/acl.rb
@@ -89,7 +89,7 @@ class Chef
end
def to_s
- "[#{collect { |ace| ace.to_s }.join(", ")}]"
+ "[#{collect(&:to_s).join(", ")}]"
end
def self.align_dword(size)
diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb
index daf043d84a..d3ebf46871 100644
--- a/lib/chef/win32/version.rb
+++ b/lib/chef/win32/version.rb
@@ -128,7 +128,7 @@ class Chef
# The operating system version is a string in the following form
# that can be split into components based on the '.' delimiter:
# MajorVersionNumber.MinorVersionNumber.BuildNumber
- os_version.split(".").collect { |version_string| version_string.to_i }
+ os_version.split(".").collect(&:to_i)
end
def get_version_ex