summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-03-20 11:19:55 -0700
committerGitHub <noreply@github.com>2018-03-20 11:19:55 -0700
commitd03860b9fe5cb8fef8698c3bfcc0cdaa28323e70 (patch)
treea906e3f7128902df22610d764bb5a7350f12ae64 /lib
parent747797aaac9dc3d900c3888a008e743d07dd8fe2 (diff)
parentad60747d58855395aebd6cf7d182ae553b70e0a2 (diff)
downloadchef-d03860b9fe5cb8fef8698c3bfcc0cdaa28323e70.tar.gz
Merge pull request #6661 from chef/lcg/package_class_perf_tweak
memoize some work in the package class
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/package.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 0011efbcf4..70483f9124 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -591,12 +591,12 @@ class Chef
# @return [Boolean] if we're doing a multipackage install or not
def multipackage?
- new_resource.package_name.is_a?(Array)
+ @multipackage_bool ||= new_resource.package_name.is_a?(Array)
end
# @return [Array] package_name(s) as an array
def package_name_array
- [ new_resource.package_name ].flatten
+ @package_name_array ||= [ new_resource.package_name ].flatten
end
# @return [Array] candidate_version(s) as an array
@@ -608,12 +608,12 @@ class Chef
# @return [Array] current_version(s) as an array
def current_version_array
- [ current_resource.version ].flatten
+ @current_version_array ||= [ current_resource.version ].flatten
end
# @return [Array] new_version(s) as an array
def new_version_array
- [ new_resource.version ].flatten.map { |v| v.to_s.empty? ? nil : v }
+ @new_version_array ||= [ new_resource.version ].flatten.map { |v| v.to_s.empty? ? nil : v }
end
# TIP: less error prone to simply always call resolved_source_array, even if you
@@ -621,11 +621,14 @@ class Chef
#
# @return [Array] new_resource.source as an array
def source_array
- if new_resource.source.nil?
- package_name_array.map { nil }
- else
- [ new_resource.source ].flatten
- end
+ @source_array ||=
+ begin
+ if new_resource.source.nil?
+ package_name_array.map { nil }
+ else
+ [ new_resource.source ].flatten
+ end
+ end
end
# Helper to handle use_package_name_for_source to convert names into local packages to install.