@@ -139,7 +139,7 @@ def rsapi_canonicalized_target_state
139139 @rsapi_canonicalized_target_state ||= begin
140140 # skip puppet's injected metaparams
141141 actual_params = @parameters . select { |k , _v | type_definition . attributes . key? k }
142- target_state = Hash [ actual_params . map { |k , v | [ k , v . rs_value ] } ]
142+ target_state = actual_params . transform_values { |v | v . rs_value }
143143 target_state = my_provider . canonicalize ( context , [ target_state ] ) . first if type_definition . feature? ( 'canonicalize' )
144144 target_state
145145 end
@@ -150,21 +150,23 @@ def rsapi_canonicalized_target_state
150150 def generate
151151 # If feature `custom_generate` has been set then call the generate function within the provider and return the given results
152152 return unless type_definition &.feature? ( 'custom_generate' )
153+
153154 should_hash = rsapi_canonicalized_target_state
154155 is_hash = rsapi_current_state
155156 title = rsapi_title
156157
157158 # Ensure that a custom `generate` method has been created within the provider
158159 raise ( Puppet ::DevError , 'No generate method found within the types provider' ) unless my_provider . respond_to? ( :generate )
160+
159161 # Call the providers custom `generate` method
160- rules_resources = my_provider . generate ( context , title , is_hash , should_hash )
162+ my_provider . generate ( context , title , is_hash , should_hash )
161163
162164 # Return array of resources
163- rules_resources
164165 end
165166
166167 def rsapi_current_state
167168 return @rsapi_current_state if @rsapi_current_state
169+
168170 # If the current state is not set, then check the cache and, if a value is
169171 # found, ensure it passes strict_check before allowing it to be used:
170172 cached_value = rsapi_provider_get_cache . get ( rsapi_title )
@@ -238,10 +240,8 @@ def to_resource_shim(resource)
238240 definition [ :attributes ] . each do |name , options |
239241 # puts "#{name}: #{options.inspect}"
240242
241- if options [ :behaviour ]
242- unless [ :read_only , :namevar , :parameter , :init_only ] . include? options [ :behaviour ]
243- raise Puppet ::ResourceError , "`#{ options [ :behaviour ] } ` is not a valid behaviour value"
244- end
243+ if options [ :behaviour ] && !( [ :read_only , :namevar , :parameter , :init_only ] . include? options [ :behaviour ] )
244+ raise Puppet ::ResourceError , "`#{ options [ :behaviour ] } ` is not a valid behaviour value"
245245 end
246246
247247 # TODO: using newparam everywhere would suppress change reporting
@@ -365,6 +365,7 @@ def flush
365365 if Puppet . settings [ :strict ] != :off && rsapi_current_state && ( rsapi_current_state [ :ensure ] == 'present' && target_state [ :ensure ] == 'present' )
366366 target_state . each do |name , value |
367367 next unless type_definition . attributes [ name ] [ :behaviour ] == :init_only && value != rsapi_current_state [ name ]
368+
368369 message = "Attempting to change `#{ name } ` init_only attribute value from `#{ rsapi_current_state [ name ] } ` to `#{ value } `"
369370 case Puppet . settings [ :strict ]
370371 when :warning
@@ -390,12 +391,12 @@ def flush
390391 end
391392
392393 def raise_missing_attrs
393- error_msg = "The following mandatory attributes were not provided:\n * " + @missing_attrs . join ( ", \n * " )
394+ error_msg = "The following mandatory attributes were not provided:\n * #{ @missing_attrs . join ( ", \n * " ) } "
394395 raise Puppet ::ResourceError , error_msg if @missing_attrs . any? && ( value ( :ensure ) != :absent && !value ( :ensure ) . nil? )
395396 end
396397
397398 def raise_missing_params
398- error_msg = "The following mandatory parameters were not provided:\n * " + @missing_params . join ( ", \n * " )
399+ error_msg = "The following mandatory parameters were not provided:\n * #{ @missing_params . join ( ", \n * " ) } "
399400 raise Puppet ::ResourceError , error_msg
400401 end
401402
@@ -426,14 +427,14 @@ def strict_check_canonicalize(current_state)
426427 # compare the clone against the current state to see if changes have been made by canonicalize
427428 return unless state_clone && ( current_state != state_clone )
428429
429- #:nocov:
430+ # :nocov:
430431 # codecov fails to register this multiline as covered, even though simplecov does.
431432 message = <<MESSAGE . strip
432433#{ type_definition . name } [#{ @title } ]#get has not provided canonicalized values.
433434Returned values: #{ current_state . inspect }
434435Canonicalized values: #{ state_clone . inspect }
435436MESSAGE
436- #:nocov:
437+ # :nocov:
437438 strict_message ( message )
438439 end
439440
@@ -448,6 +449,7 @@ def strict_check_title_parameter(current_state)
448449 self . class . title_patterns . each do |regexp , symbols |
449450 captures = regexp . match ( current_state [ :title ] )
450451 next if captures . nil?
452+
451453 symbols . zip ( captures [ 1 ..-1 ] ) . each do |symbol_and_lambda , capture |
452454 # The Resource API does not support passing procs in title_patterns
453455 # so, unlike Puppet::Resource, we do not need to handle that here.
@@ -461,15 +463,15 @@ def strict_check_title_parameter(current_state)
461463
462464 namevars = type_definition . namevars . reject { |namevar | title_hash [ namevar ] == rsapi_title [ namevar ] }
463465
464- #:nocov:
466+ # :nocov:
465467 # codecov fails to register this multiline as covered, even though simplecov does.
466468 message = <<MESSAGE . strip
467469#{ type_definition . name } [#{ @title } ]#get has provided a title attribute which does not match all namevars.
468470Namevars which do not match: #{ namevars . inspect }
469471Returned parsed title hash: #{ title_hash . inspect }
470472Expected hash: #{ rsapi_title . inspect }
471473MESSAGE
472- #:nocov:
474+ # :nocov:
473475 strict_message ( message )
474476 end
475477
@@ -528,7 +530,7 @@ def self.parse_title_patterns(patterns)
528530 end
529531 end
530532 end
531- module_function :register_type # rubocop:disable Style/AccessModifierDeclarations
533+ module_function :register_type
532534
533535 def load_provider ( type_name )
534536 class_name = class_name_from_type_name ( type_name )
@@ -557,14 +559,14 @@ def load_provider(type_name)
557559 raise Puppet ::DevError , "provider class Puppet::Provider::#{ class_name } ::#{ class_name } not found in puppet/provider/#{ type_name } /#{ type_name } "
558560 end
559561 end
560- module_function :load_provider # rubocop:disable Style/AccessModifierDeclarations
562+ module_function :load_provider
561563
562564 def load_default_provider ( class_name , type_name_sym )
563565 # loads the "puppet/provider/#{type_name}/#{type_name}" file through puppet
564566 Puppet ::Type . type ( type_name_sym ) . provider ( type_name_sym )
565567 Puppet ::Provider . const_get ( class_name , false ) . const_get ( class_name , false )
566568 end
567- module_function :load_default_provider # rubocop:disable Style/AccessModifierDeclarations
569+ module_function :load_default_provider
568570
569571 def load_device_provider ( class_name , type_name_sym , device_class_name , device_name_sym )
570572 # loads the "puppet/provider/#{type_name}/#{device_name}" file through puppet
@@ -576,13 +578,13 @@ def load_device_provider(class_name, type_name_sym, device_class_name, device_na
576578 load_default_provider ( class_name , type_name_sym )
577579 end
578580 end
579- module_function :load_device_provider # rubocop:disable Style/AccessModifierDeclarations
581+ module_function :load_device_provider
580582
581583 # keeps the existing register API format. e.g. Puppet::ResourceApi.register_type
582584 def register_transport ( schema )
583585 Puppet ::ResourceApi ::Transport . register ( schema )
584586 end
585- module_function :register_transport # rubocop:disable Style/AccessModifierDeclarations
587+ module_function :register_transport
586588
587589 def self . class_name_from_type_name ( type_name )
588590 type_name . to_s . split ( '_' ) . map ( &:capitalize ) . join
0 commit comments