summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivek Singh <vivek.singh@msystechnologies.com>2020-09-19 08:20:55 +0530
committerVivek Singh <vivek.singh@msystechnologies.com>2020-09-19 08:29:12 +0530
commita5381c29675cf67852353db2cf7e67c62f737e7c (patch)
tree39c0323ba4b107224d4fb56edf83fa69bb9e5747
parenta923109af69d5cb305d3f2c2ca6da8c0397f874e (diff)
downloadchef-a5381c29675cf67852353db2cf7e67c62f737e7c.tar.gz
dpkg package DRY up the code
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-rw-r--r--chef-config/lib/chef-config/mixin/train_transport.rb2
-rw-r--r--lib/chef/provider/package/dpkg.rb15
2 files changed, 4 insertions, 13 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..0edac67a28 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 { |k| k.to_sym } # return symbolized keys to match Train.options()
else
nil
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).