summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-07-05 13:26:53 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-07-05 13:26:53 -0700
commit3b10f9ca503dcbce747241281b9151d3d010f9ef (patch)
tree2e90f78a6910a4c673e19045a7f0627f1fc49382
parent2a4916b7f01940d1199c35645c1b2172f5bd74b2 (diff)
downloadchef-3b10f9ca503dcbce747241281b9151d3d010f9ef.tar.gz
Style/SymbolProc
enforce pretzels. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-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
-rw-r--r--spec/functional/resource/cookbook_file_spec.rb4
-rw-r--r--spec/functional/resource/dsc_script_spec.rb8
-rw-r--r--spec/functional/resource/template_spec.rb2
-rw-r--r--spec/integration/client/client_spec.rb4
-rw-r--r--spec/integration/recipes/lwrp_inline_resources_spec.rb4
-rw-r--r--spec/stress/win32/security_spec.rb2
-rw-r--r--spec/support/shared/functional/file_resource.rb4
-rw-r--r--spec/support/shared/functional/http.rb36
-rw-r--r--spec/support/shared/functional/securable_resource.rb10
-rw-r--r--spec/unit/chef_fs/file_system/repository/directory_spec.rb2
-rw-r--r--spec/unit/chef_fs/parallelizer.rb2
-rw-r--r--spec/unit/knife/node_bulk_delete_spec.rb2
-rw-r--r--spec/unit/lwrp_spec.rb2
-rw-r--r--spec/unit/property/state_spec.rb2
-rw-r--r--spec/unit/property/validation_spec.rb2
-rw-r--r--spec/unit/property_spec.rb2
-rw-r--r--spec/unit/recipe_spec.rb2
-rw-r--r--spec/unit/resource/template_spec.rb2
-rw-r--r--spec/unit/resource_collection/stepable_iterator_spec.rb4
-rw-r--r--spec/unit/shell/model_wrapper_spec.rb2
-rw-r--r--spec/unit/version_class_spec.rb4
76 files changed, 121 insertions, 161 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
diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb
index d127413c73..6e964a6499 100644
--- a/spec/functional/resource/cookbook_file_spec.rb
+++ b/spec/functional/resource/cookbook_file_spec.rb
@@ -25,9 +25,7 @@ describe Chef::Resource::CookbookFile do
let(:source) { "java.response" }
let(:cookbook_name) { "java" }
let(:expected_content) do
- content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb") do |f|
- f.read
- end
+ content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb", &:read)
content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
content
end
diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb
index 8488fe09ed..224141c0f8 100644
--- a/spec/functional/resource/dsc_script_spec.rb
+++ b/spec/functional/resource/dsc_script_spec.rb
@@ -349,9 +349,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
let(:config_param_section) { config_params }
let(:config_flags) { { "#{dsc_user_prefix_param_name}": (dsc_user_prefix).to_s, "#{dsc_user_suffix_param_name}": (dsc_user_suffix).to_s } }
it "does not directly contain the user name" do
- configuration_script_content = ::File.open(dsc_test_resource.command) do |file|
- file.read
- end
+ configuration_script_content = ::File.open(dsc_test_resource.command, &:read)
expect(configuration_script_content.include?(dsc_user)).to be(false)
end
it_behaves_like "a dsc_script with configuration data"
@@ -361,9 +359,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
let(:dsc_user_code) { dsc_user_env_code }
it "does not directly contain the user name" do
- configuration_script_content = ::File.open(dsc_test_resource.command) do |file|
- file.read
- end
+ configuration_script_content = ::File.open(dsc_test_resource.command, &:read)
expect(configuration_script_content.include?(dsc_user)).to be(false)
end
it_behaves_like "a dsc_script with configuration data"
diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb
index 679ffe661a..feef97dd27 100644
--- a/spec/functional/resource/template_spec.rb
+++ b/spec/functional/resource/template_spec.rb
@@ -21,7 +21,7 @@ require "spec_helper"
describe Chef::Resource::Template do
def binread(file)
- File.open(file, "rb") { |f| f.read }
+ File.open(file, "rb", &:read)
end
include_context Chef::Resource::File
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index 7ae255eabf..68cfd015ab 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -21,9 +21,7 @@ describe "chef-client" do
# just a normal file
# (expected_content should be uncompressed)
@api.get("/recipes.tgz", 200) do
- File.open(recipes_filename, "rb") do |f|
- f.read
- end
+ File.open(recipes_filename, "rb", &:read)
end
end
diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb
index 75516203b3..b96fa1d67d 100644
--- a/spec/integration/recipes/lwrp_inline_resources_spec.rb
+++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb
@@ -152,7 +152,7 @@ describe "LWRPs with inline resources" do
EOM
result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" --no-color -F doc -o 'x::default'", cwd: chef_dir)
- actual = result.stdout.lines.map { |l| l.chomp }.join("\n")
+ actual = result.stdout.lines.map(&:chomp).join("\n")
expected = <<EOM
* x_my_machine[me] action create
* x_do_nothing[a] action create (up to date)
@@ -163,7 +163,7 @@ describe "LWRPs with inline resources" do
* x_do_nothing[b] action create (up to date)
(up to date)
EOM
- expected = expected.lines.map { |l| l.chomp }.join("\n")
+ expected = expected.lines.map(&:chomp).join("\n")
expect(actual).to include(expected)
result.error!
end
diff --git a/spec/stress/win32/security_spec.rb b/spec/stress/win32/security_spec.rb
index 0280398ad5..8929a2ff74 100644
--- a/spec/stress/win32/security_spec.rb
+++ b/spec/stress/win32/security_spec.rb
@@ -50,7 +50,7 @@ describe "Chef::ReservedNames::Win32::Security", :windows_only do
it "should not leak when retrieving and reading the ACE from a file", :volatile do
expect do
- sids = Chef::ReservedNames::Win32::Security::SecurableObject.new(@monkeyfoo).security_descriptor.dacl.select { |ace| ace.sid }
+ sids = Chef::ReservedNames::Win32::Security::SecurableObject.new(@monkeyfoo).security_descriptor.dacl.select(&:sid)
GC.start
end.not_to leak_memory(warmup: 50, iterations: 100)
end
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index db947614b3..114971641d 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -392,9 +392,7 @@ shared_examples_for "a configured file resource" do
end
def binread(file)
- content = File.open(file, "rb") do |f|
- f.read
- end
+ content = File.open(file, "rb", &:read)
content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
content
end
diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb
index 7450f28e35..58189e543f 100644
--- a/spec/support/shared/functional/http.rb
+++ b/spec/support/shared/functional/http.rb
@@ -30,9 +30,7 @@ module ChefHTTPShared
end
def binread(file)
- content = File.open(file, "rb") do |f|
- f.read
- end
+ content = File.open(file, "rb", &:read)
content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
content
end
@@ -53,25 +51,19 @@ module ChefHTTPShared
# just a normal file
# (expected_content should be uncompressed)
@api.get("/nyan_cat.png", 200) do
- File.open(nyan_uncompressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_uncompressed_filename, "rb", &:read)
end
# this ends in .gz, we do not uncompress it and drop it on the filesystem as a .gz file (the internet often lies)
# (expected_content should be compressed)
@api.get("/nyan_cat.png.gz", 200, nil, { "Content-Type" => "application/gzip", "Content-Encoding" => "gzip" } ) do
- File.open(nyan_compressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_compressed_filename, "rb", &:read)
end
# this is an uncompressed file that was compressed by some mod_gzip-ish webserver thingy, so we will expand it
# (expected_content should be uncompressed)
@api.get("/nyan_cat_compressed.png", 200, nil, { "Content-Type" => "application/gzip", "Content-Encoding" => "gzip" } ) do
- File.open(nyan_compressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_compressed_filename, "rb", &:read)
end
#
@@ -84,9 +76,7 @@ module ChefHTTPShared
"Content-Length" => nyan_uncompressed_size.to_s,
}
) do
- File.open(nyan_uncompressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_uncompressed_filename, "rb", &:read)
end
# (expected_content should be uncompressed)
@@ -97,9 +87,7 @@ module ChefHTTPShared
"Content-Encoding" => "gzip",
}
) do
- File.open(nyan_compressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_compressed_filename, "rb", &:read)
end
#
@@ -112,9 +100,7 @@ module ChefHTTPShared
"Content-Length" => (nyan_uncompressed_size + 1).to_s,
}
) do
- File.open(nyan_uncompressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_uncompressed_filename, "rb", &:read)
end
# (expected_content should be uncompressed)
@@ -125,9 +111,7 @@ module ChefHTTPShared
"Content-Encoding" => "gzip",
}
) do
- File.open(nyan_compressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_compressed_filename, "rb", &:read)
end
#
@@ -141,9 +125,7 @@ module ChefHTTPShared
"Transfer-Encoding" => "anything",
}
) do
- File.open(nyan_uncompressed_filename, "rb") do |f|
- f.read
- end
+ File.open(nyan_uncompressed_filename, "rb", &:read)
end
#
diff --git a/spec/support/shared/functional/securable_resource.rb b/spec/support/shared/functional/securable_resource.rb
index 6705c8e2d8..010ef27f47 100644
--- a/spec/support/shared/functional/securable_resource.rb
+++ b/spec/support/shared/functional/securable_resource.rb
@@ -89,7 +89,7 @@ shared_context "use Windows permissions", :windows_only do
end
def explicit_aces
- descriptor.dacl.select { |ace| ace.explicit? }
+ descriptor.dacl.select(&:explicit?)
end
def extract_ace_properties(aces)
@@ -560,16 +560,12 @@ shared_examples_for "a securable resource without existing target" do
# On certain flavors of Windows the default list of ACLs sometimes includes
# non-inherited ACLs. Filter them out here.
- parent_inherited_acls = parent_acls.dacl.collect do |ace|
- ace.inherited?
- end
+ parent_inherited_acls = parent_acls.dacl.collect(&:inherited?)
resource.run_action(:create)
# Similarly filter out the non-inherited ACLs
- resource_inherited_acls = descriptor.dacl.collect do |ace|
- ace.inherited?
- end
+ resource_inherited_acls = descriptor.dacl.collect(&:inherited?)
expect(resource_inherited_acls).to eq(parent_inherited_acls)
end
diff --git a/spec/unit/chef_fs/file_system/repository/directory_spec.rb b/spec/unit/chef_fs/file_system/repository/directory_spec.rb
index 5b2a0a47b8..ec147ba6a8 100644
--- a/spec/unit/chef_fs/file_system/repository/directory_spec.rb
+++ b/spec/unit/chef_fs/file_system/repository/directory_spec.rb
@@ -106,7 +106,7 @@ describe Chef::ChefFS::FileSystem::Repository::Directory do
end
it "filters invalid names" do
- expect(test_directory.children.map { |c| c.name }).to eql %w{ test1.json test2.json test3.json }
+ expect(test_directory.children.map(&:name)).to eql %w{ test1.json test2.json test3.json }
end
end
diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb
index 32e56c4231..d43e48b7bc 100644
--- a/spec/unit/chef_fs/parallelizer.rb
+++ b/spec/unit/chef_fs/parallelizer.rb
@@ -443,7 +443,7 @@ describe Chef::ChefFS::Parallelizer do
threads = 0.upto(99).map do |i|
Thread.new { outputs[i] = parallelizers[i].to_a }
end
- threads.each { |thread| thread.join }
+ threads.each(&:join)
outputs.each { |output| expect(output.sort).to eq(2.upto(501).to_a) }
end
end
diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb
index b97df004a3..db9e2caab1 100644
--- a/spec/unit/knife/node_bulk_delete_spec.rb
+++ b/spec/unit/knife/node_bulk_delete_spec.rb
@@ -44,7 +44,7 @@ describe Chef::Knife::NodeBulkDelete do
# I hate not having == defined for anything :(
actual = @knife.all_nodes
expect(actual.keys).to match_array(expected.keys)
- expect(actual.values.map { |n| n.name }).to match_array(%w{adam brent jacob})
+ expect(actual.values.map(&:name)).to match_array(%w{adam brent jacob})
end
end
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 5c1bdb687c..def981801e 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -199,7 +199,7 @@ describe "LWRP" do
end
it "should create a method for each attribute" do
- expect(get_lwrp(:lwrp_foo).new("blah").methods.map { |m| m.to_sym }).to include(:monkey)
+ expect(get_lwrp(:lwrp_foo).new("blah").methods.map(&:to_sym)).to include(:monkey)
end
it "should build attribute methods that respect validation rules" do
diff --git a/spec/unit/property/state_spec.rb b/spec/unit/property/state_spec.rb
index 1283fd2456..a6428e8617 100644
--- a/spec/unit/property/state_spec.rb
+++ b/spec/unit/property/state_spec.rb
@@ -29,7 +29,7 @@ describe "Chef::Resource#identity and #state" do
return "<nothing>" if values.size == 0
return values[0].inspect if values.size == 1
- "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
+ "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}"
end
def self.with_property(*properties, &block)
diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb
index 514d1666be..dab2be8000 100644
--- a/spec/unit/property/validation_spec.rb
+++ b/spec/unit/property/validation_spec.rb
@@ -56,7 +56,7 @@ describe "Chef::Resource.property validation" do
return "<nothing>" if values.size == 0
return values[0].inspect if values.size == 1
- "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
+ "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}"
end
def self.with_property(*properties, &block)
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 50e15f4505..1fcbb77e8e 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -52,7 +52,7 @@ describe "Chef::Resource.property" do
return "<nothing>" if values.size == 0
return values[0].inspect if values.size == 1
- "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
+ "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}"
end
def self.with_property(*properties, &block)
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index a4fdbd9809..f2ec175243 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -94,7 +94,7 @@ describe Chef::Recipe do
end
end
- expect(run_context.resource_collection.map { |r| r.name }).to eql(%w{monkey dog cat})
+ expect(run_context.resource_collection.map(&:name)).to eql(%w{monkey dog cat})
end
it "should return the new resource after creating it" do
diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb
index 3c16f99c4a..2f8e234c85 100644
--- a/spec/unit/resource/template_spec.rb
+++ b/spec/unit/resource/template_spec.rb
@@ -147,7 +147,7 @@ describe Chef::Resource::Template do
end
it "compiles helper methods with arguments into a module" do
- resource.helper(:shout) { |quiet| quiet.upcase }
+ resource.helper(:shout, &:upcase)
modules = resource.helper_modules
o = Object.new
modules.each { |m| o.extend(m) }
diff --git a/spec/unit/resource_collection/stepable_iterator_spec.rb b/spec/unit/resource_collection/stepable_iterator_spec.rb
index 6354b1b7fb..ec831c9afe 100644
--- a/spec/unit/resource_collection/stepable_iterator_spec.rb
+++ b/spec/unit/resource_collection/stepable_iterator_spec.rb
@@ -72,7 +72,7 @@ describe Chef::ResourceCollection::StepableIterator do
@collection << lambda { @snitch_var = 42 }
@iterator = CRSI.for_collection(@collection)
- @iterator.each { |proc| proc.call }
+ @iterator.each(&:call)
end
it "allows the iteration to be paused" do
@@ -124,7 +124,7 @@ describe Chef::ResourceCollection::StepableIterator do
it "allows the iteration to start by being stepped" do
@snitch_var = nil
@iterator = CRSI.for_collection(@collection)
- @iterator.iterate_on(:element) { |proc| proc.call }
+ @iterator.iterate_on(:element, &:call)
@iterator.step
expect(@iterator.position).to eq(1)
expect(@snitch_var).to eq(23)
diff --git a/spec/unit/shell/model_wrapper_spec.rb b/spec/unit/shell/model_wrapper_spec.rb
index bcce7c1a08..7ca5f74bef 100644
--- a/spec/unit/shell/model_wrapper_spec.rb
+++ b/spec/unit/shell/model_wrapper_spec.rb
@@ -57,7 +57,7 @@ describe Shell::ModelWrapper do
end
it "maps the listed nodes when given a block" do
- expect(@wrapper.all { |n| n.name }.sort.reverse).to eq(%w{yummy sammich})
+ expect(@wrapper.all(&:name).sort.reverse).to eq(%w{yummy sammich})
end
end
diff --git a/spec/unit/version_class_spec.rb b/spec/unit/version_class_spec.rb
index 2126b18ffb..c6848491ee 100644
--- a/spec/unit/version_class_spec.rb
+++ b/spec/unit/version_class_spec.rb
@@ -105,7 +105,7 @@ describe Chef::Version do
a = %w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}.map do |s|
Chef::Version.new(s)
end
- got = a.sort.map { |v| v.to_s }
+ got = a.sort.map(&:to_s)
expect(got).to eq(%w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1})
end
@@ -113,7 +113,7 @@ describe Chef::Version do
a = %w{9.8.7 1.0.0 1.2.3 4.4.6 4.5.6 0.8.6 4.5.5 5.9.8 3.5.7}.map do |s|
Chef::Version.new(s)
end
- got = a.sort.map { |v| v.to_s }
+ got = a.sort.map(&:to_s)
expect(got).to eq(%w{0.8.6 1.0.0 1.2.3 3.5.7 4.4.6 4.5.5 4.5.6 5.9.8 9.8.7})
end