Add warning when returning DEFAULT_ATTRIBUTE (#2934)

When the anonymous DEFAULT_ATTRIBUTE class is used, log a warning.

We now pass in the attribute name to that class so it can be used in the
log message.

Signed-off-by: Trevor Bramble <tbramble@chef.io>
This commit is contained in:
Trevor Bramble 2018-04-11 12:11:01 -07:00 committed by Jared Quick
parent 0d7688092a
commit 6bfe741625

View file

@ -6,7 +6,17 @@ module Inspec
attr_writer :value
DEFAULT_ATTRIBUTE = Class.new do
def initialize(name)
@name = name
end
def method_missing(*_)
Inspec::Log.warn(
"Returning DEFAULT_ATTRIBUTE for '#{@name}'. "\
"Use --attrs to provide a value for '#{@name}' or specify a default "\
"value with `attribute('#{@name}', default: 'somedefault', ...)`.",
)
self
end
@ -27,7 +37,7 @@ module Inspec
end
def default
@opts.key?(:default) ? @opts[:default] : DEFAULT_ATTRIBUTE.new
@opts.key?(:default) ? @opts[:default] : DEFAULT_ATTRIBUTE.new(@name)
end
def title