mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
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:
parent
0d7688092a
commit
6bfe741625
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue