diff options
author | Tim Smith <tsmith@chef.io> | 2020-09-23 19:41:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-23 19:41:34 -0700 |
commit | c3932fabf25e9f4de4893f706417c2e42929a95c (patch) | |
tree | a2521fc477f52368d02dbd7d727afb9e09dcb9f6 | |
parent | a3446ea33bbaf519b19ac47cf7aef673f269de51 (diff) | |
parent | 5fac1a83d4c89d361be11c4afa8fedd482a7eb9d (diff) | |
download | chef-c3932fabf25e9f4de4893f706417c2e42929a95c.tar.gz |
Merge pull request #10447 from chef/VSingh/simplify-hash
Simplify Hash transforms & minor code refactoring
-rw-r--r-- | chef-config/lib/chef-config/mixin/train_transport.rb | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/workstation_config_loader.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/dpkg.rb | 15 |
3 files changed, 5 insertions, 14 deletions
diff --git a/chef-config/lib/chef-config/mixin/train_transport.rb b/chef-config/lib/chef-config/mixin/train_transport.rb index aaf81fd8cd..942f0ab3b7 100644 --- a/chef-config/lib/chef-config/mixin/train_transport.rb +++ b/chef-config/lib/chef-config/mixin/train_transport.rb @@ -44,7 +44,7 @@ module ChefConfig # host names must be specified in credentials file as ['foo.example.org'] with quotes if !credentials.nil? && !credentials[profile].nil? - credentials[profile].map { |k, v| [k.to_sym, v] }.to_h # return symbolized keys to match Train.options() + credentials[profile].transform_keys(&:to_sym) # return symbolized keys to match Train.options() else nil end diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb index 8f481a7a89..bbec74911b 100644 --- a/chef-config/lib/chef-config/workstation_config_loader.rb +++ b/chef-config/lib/chef-config/workstation_config_loader.rb @@ -166,7 +166,7 @@ module ChefConfig when "client_key" extract_key(value, :client_key, :client_key_contents) when "knife" - Config.knife.merge!(Hash[value.map { |k, v| [k.to_sym, v] }]) + Config.knife.merge!(value.transform_keys(&:to_sym)) else Config[key.to_sym] = value end diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb index 08829e9b26..b2d1678caa 100644 --- a/lib/chef/provider/package/dpkg.rb +++ b/lib/chef/provider/package/dpkg.rb @@ -164,10 +164,7 @@ class Chef # # @return [Hash] Mapping of package names to sources def name_sources - @name_sources = - begin - Hash[*package_name_array.zip(resolved_source_array).flatten] - end + @name_sources ||= Hash[*package_name_array.zip(resolved_source_array).flatten] end # Helper to construct Hash of names-to-package-information. @@ -186,17 +183,11 @@ class Chef end def name_candidate_version - @name_candidate_version ||= - begin - Hash[name_pkginfo.map { |k, v| [k, v ? v.split("\t")[1].strip : nil] }] - end + @name_candidate_version ||= name_pkginfo.transform_values { |v| v ? v.split("\t")[1]&.strip : nil } end def name_package_name - @name_package_name ||= - begin - Hash[name_pkginfo.map { |k, v| [k, v ? v.split("\t")[0] : nil] }] - end + @name_package_name ||= name_pkginfo.transform_values { |v| v ? v.split("\t")[0] : nil } end # Return candidate version array from pkg-deb -W against the source file(s). |