Skip to content

Commit 38beade

Browse files
committed
rubocop unsafe corrections
1 parent a489d72 commit 38beade

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def retry_invoke_dsc_resource(context, max_retry_count, retry_wait_interval_secs
353353
# @return [Boolean, Void] returns true/false if the resource is/isn't in the desired state and
354354
# the validation mode is set to resource, otherwise nil.
355355
def insync?(context, name, _property_name, _is_hash, should_hash)
356-
return nil if should_hash[:validation_mode] != 'resource'
356+
return false if should_hash[:validation_mode] != 'resource'
357357

358358
prior_result = fetch_cached_hashes(@cached_test_results, [name])
359359
prior_result.empty? ? invoke_test_method(context, name, should_hash) : prior_result.first[:in_desired_state]
@@ -787,7 +787,7 @@ def munge_psmodulepath(resource)
787787
# @return [String] An array of lines of PowerShell to instantiate PSCredentialObjects and store them in variables
788788
def prepare_credentials(resource)
789789
credentials_block = []
790-
resource[:parameters].each do |_property_name, property_hash|
790+
resource[:parameters].each_value do |property_hash|
791791
next unless property_hash[:mof_type] == 'PSCredential'
792792
next if property_hash[:value].nil?
793793

@@ -822,7 +822,7 @@ def format_pscredential(variable_name, credential_hash)
822822
# @return [String] An array of lines of PowerShell to instantiate CIM Instances and store them in variables
823823
def prepare_cim_instances(resource)
824824
cim_instances_block = []
825-
resource[:parameters].each do |_property_name, property_hash|
825+
resource[:parameters].each_value do |property_hash|
826826
next unless property_hash[:mof_is_embedded]
827827
next if property_hash[:mof_type] == 'PSCredential' # Credentials are handled separately
828828

@@ -836,7 +836,7 @@ def prepare_cim_instances(resource)
836836
cim_instance_hashes.each do |instance|
837837
variable_name = random_variable_name
838838
class_name = instance['cim_instance_type']
839-
properties = instance.reject { |k, _v| k == 'cim_instance_type' }
839+
properties = instance.except('cim_instance_type')
840840
cim_instances_block << format_ciminstance(variable_name, class_name, properties)
841841
instantiated_variables.merge!(variable_name => instance)
842842
end
@@ -950,7 +950,7 @@ def invoke_params(resource) # rubocop:disable Metrics/MethodLength
950950
params_block = params_block.gsub("#{param_block_name} = @()", "#{param_block_name} = [#{properties[:mof_type]}]@()")
951951
end
952952
# HACK: make CIM instances work:
953-
resource[:parameters].select { |_key, hash| hash[:mof_is_embedded] && hash[:mof_type].include?('[]') }.each do |_property_name, property_hash|
953+
resource[:parameters].select { |_key, hash| hash[:mof_is_embedded] && hash[:mof_type].include?('[]') }.each_value do |property_hash|
954954
formatted_property_hash = interpolate_variables(format(property_hash[:value]))
955955
params_block = params_block.gsub(formatted_property_hash, "[CimInstance[]]#{formatted_property_hash}")
956956
end
@@ -1012,11 +1012,9 @@ def unwrap(value)
10121012
end
10131013
unwrapped
10141014
when Array
1015-
unwrapped = []
1016-
value.each do |v|
1017-
unwrapped << unwrap(v)
1015+
unwrapped = value.map do |v|
1016+
unwrap(v)
10181017
end
1019-
unwrapped
10201018
else
10211019
value
10221020
end
@@ -1037,11 +1035,9 @@ def unwrap_string(value)
10371035
end
10381036
unwrapped
10391037
when Array
1040-
unwrapped = []
1041-
value.each do |v|
1042-
unwrapped << unwrap_string(v)
1038+
unwrapped = value.map do |v|
1039+
unwrap_string(v)
10431040
end
1044-
unwrapped
10451041
else
10461042
value
10471043
end

spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@
10501050

10511051
let(:name) { { name: 'foo', dsc_name: 'bar' } }
10521052
let(:should_hash) { name.merge(dsc_ensure: 'present') }
1053-
let(:test_properties) { should_hash.reject { |k, _v| k == :name } }
1053+
let(:test_properties) { should_hash.except(:name) }
10541054
let(:invoke_dsc_resource_data) { nil }
10551055

10561056
before do

0 commit comments

Comments
 (0)