Accept a refactornig suggestion

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2020-01-06 19:21:12 -05:00
parent 835bd2be8c
commit 3a97e5d75b

View file

@ -78,27 +78,18 @@ module Inspec
# Return FalseClass if the update contained no useful information # Return FalseClass if the update contained no useful information
# and a retry should not be attempted # and a retry should not be attempted
def update_from_opts(opts) def update_from_opts(opts)
changed = false changed = @archive_shasum != opts[:sha256]
@archive_shasum = opts[:sha256]
old_val = @archive_shasum
new_val = opts[:sha256]
unless old_val == new_val
@archive_shasum = new_val
changed = true
end
changed changed
end end
# Helper for above. # Helper for above; usful when the subclass ivars whose
# names exactly match the names of the fetcher options.
def update_ivar_from_opt(opt_name, opts) def update_ivar_from_opt(opt_name, opts)
ivar_sym = "@#{opt_name}".to_sym ivar_sym = "@#{opt_name}".to_sym
old_val = instance_variable_get(ivar_sym) changed = instance_variable_get(ivar_sym) != opts[opt_name]
new_val = opts[opt_name] instance_variable_set(ivar_sym, opts[opt_name])
return false if old_val == new_val changed
instance_variable_set(ivar_sym, new_val)
true
end end
# #