mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Modify Hashlike behavior when values are nil
Exclude nil-valued keys when RunData acts like a Hash Add non_nil? for clarity when people are calling key? and meaning not-nil Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
10e28c6895
commit
49f3e94133
1 changed files with 9 additions and 2 deletions
|
@ -1,12 +1,19 @@
|
|||
|
||||
module Inspec
|
||||
module HashLikeStruct
|
||||
# Only list keys whose value are non-nil
|
||||
def keys
|
||||
members
|
||||
members.reject { |k| self[k].nil? }
|
||||
end
|
||||
|
||||
# Only list non-nil members for backwards compatibility
|
||||
def key?(item)
|
||||
members.include?(item)
|
||||
members.include?(item) && non_nil?(item)
|
||||
end
|
||||
|
||||
# This is provided for clarity - many locations make this test
|
||||
def non_nil?(item)
|
||||
!self[item].nil?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue