@@ -91,7 +91,7 @@ def type_definition
91
91
apply_to_device
92
92
end
93
93
94
- define_method ( :initialize ) do | attributes |
94
+ def initialize ( attributes )
95
95
# $stderr.puts "A: #{attributes.inspect}"
96
96
if attributes . is_a? Puppet ::Resource
97
97
@title = attributes . title
@@ -119,7 +119,7 @@ def type_definition
119
119
# the `Puppet::Resource::Ral.find` method, when `instances` does not return a match, uses a Hash with a `:name` key to create
120
120
# an "absent" resource. This is often hit by `puppet resource`. This needs to work, even if the namevar is not called `name`.
121
121
# This bit here relies on the default `title_patterns` (see below) to match the title back to the first (and often only) namevar
122
- if definition [ : attributes] [ :name ] . nil? && attributes [ :title ] . nil?
122
+ if type_definition . attributes [ :name ] . nil? && attributes [ :title ] . nil?
123
123
attributes [ :title ] = attributes . delete ( :name )
124
124
if attributes [ :title ] . nil? && !type_definition . namevars . empty?
125
125
attributes [ :title ] = @title
@@ -137,7 +137,7 @@ def to_resource
137
137
to_resource_shim ( super )
138
138
end
139
139
140
- define_method ( :to_resource_shim ) do | resource |
140
+ def to_resource_shim ( resource )
141
141
resource_hash = Hash [ resource . keys . map { |k | [ k , resource [ k ] ] } ]
142
142
resource_hash [ :title ] = resource . title
143
143
ResourceShim . new ( resource_hash , type_definition . name , type_definition . namevars , type_definition . attributes , catalog )
@@ -244,7 +244,7 @@ def to_resource
244
244
end
245
245
end
246
246
247
- define_singleton_method ( :instances ) do
247
+ def self . instances
248
248
# puts 'instances'
249
249
# force autoloading of the provider
250
250
provider ( type_definition . name )
@@ -268,7 +268,7 @@ def to_resource
268
268
end
269
269
end
270
270
271
- define_method ( :refresh_current_state ) do
271
+ def refresh_current_state
272
272
@rsapi_current_state = if type_definition . feature? ( 'simple_get_filter' )
273
273
my_provider . get ( context , [ title ] ) . find { |h | namevar_match? ( h ) }
274
274
else
@@ -290,7 +290,7 @@ def cache_current_state(resource_hash)
290
290
strict_check ( @rsapi_current_state ) if type_definition . feature? ( 'canonicalize' )
291
291
end
292
292
293
- define_method ( :retrieve ) do
293
+ def retrieve
294
294
refresh_current_state unless @rsapi_current_state
295
295
296
296
Puppet . debug ( "Current State: #{ @rsapi_current_state . inspect } " )
@@ -304,13 +304,13 @@ def cache_current_state(resource_hash)
304
304
result
305
305
end
306
306
307
- define_method ( : namevar_match?) do | item |
307
+ def namevar_match? ( item )
308
308
context . type . namevars . all? do |namevar |
309
309
item [ namevar ] == @parameters [ namevar ] . value if @parameters [ namevar ] . respond_to? :value
310
310
end
311
311
end
312
312
313
- define_method ( :flush ) do
313
+ def flush
314
314
raise_missing_attrs
315
315
316
316
# puts 'flush'
@@ -328,7 +328,7 @@ def cache_current_state(resource_hash)
328
328
# enforce init_only attributes
329
329
if Puppet . settings [ :strict ] != :off && @rsapi_current_state && ( @rsapi_current_state [ :ensure ] == 'present' && target_state [ :ensure ] == 'present' )
330
330
target_state . each do |name , value |
331
- next unless definition [ : attributes] [ name ] [ :behaviour ] == :init_only && value != @rsapi_current_state [ name ]
331
+ next unless type_definition . attributes [ name ] [ :behaviour ] == :init_only && value != @rsapi_current_state [ name ]
332
332
message = "Attempting to change `#{ name } ` init_only attribute value from `#{ @rsapi_current_state [ name ] } ` to `#{ value } `"
333
333
case Puppet . settings [ :strict ]
334
334
when :warning
@@ -350,17 +350,17 @@ def cache_current_state(resource_hash)
350
350
@rsapi_current_state = target_state
351
351
end
352
352
353
- define_method ( :raise_missing_attrs ) do
353
+ def raise_missing_attrs
354
354
error_msg = "The following mandatory attributes were not provided:\n * " + @missing_attrs . join ( ", \n * " )
355
355
raise Puppet ::ResourceError , error_msg if @missing_attrs . any? && ( value ( :ensure ) != :absent && !value ( :ensure ) . nil? )
356
356
end
357
357
358
- define_method ( :raise_missing_params ) do
358
+ def raise_missing_params
359
359
error_msg = "The following mandatory parameters were not provided:\n * " + @missing_params . join ( ", \n * " )
360
360
raise Puppet ::ResourceError , error_msg
361
361
end
362
362
363
- define_method ( :strict_check ) do | current_state |
363
+ def strict_check ( current_state )
364
364
return if Puppet . settings [ :strict ] == :off
365
365
366
366
# if strict checking is on we must notify if the values are changed by canonicalize
@@ -374,7 +374,7 @@ def cache_current_state(resource_hash)
374
374
#:nocov:
375
375
# codecov fails to register this multiline as covered, even though simplecov does.
376
376
message = <<MESSAGE . strip
377
- #{ definition [ : name] } [#{ @title } ]#get has not provided canonicalized values.
377
+ #{ type_definition . name } [#{ @title } ]#get has not provided canonicalized values.
378
378
Returned values: #{ current_state . inspect }
379
379
Canonicalized values: #{ state_clone . inspect }
380
380
MESSAGE
@@ -387,7 +387,7 @@ def cache_current_state(resource_hash)
387
387
raise Puppet ::DevError , message
388
388
end
389
389
390
- return nil
390
+ nil
391
391
end
392
392
393
393
define_singleton_method ( :context ) do
@@ -398,9 +398,9 @@ def context
398
398
self . class . context
399
399
end
400
400
401
- define_singleton_method ( :title_patterns ) do
402
- @title_patterns ||= if definition . key? :title_patterns
403
- parse_title_patterns ( definition [ :title_patterns ] )
401
+ def self . title_patterns
402
+ @title_patterns ||= if type_definition . definition . key? :title_patterns
403
+ parse_title_patterns ( type_definition . definition [ :title_patterns ] )
404
404
else
405
405
[ [ %r{(.*)}m , [ [ type_definition . namevars . first ] ] ] ]
406
406
end
0 commit comments