Rely on copy of to_hash in objects/input.rb to avoid duplication

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-10-02 12:22:20 -04:00
parent 51812a9e4e
commit 36db8b9a7b
3 changed files with 5 additions and 21 deletions

View file

@ -318,21 +318,6 @@ module Inspec
!current_value.is_a? NO_VALUE_SET
end
#--------------------------------------------------------------------------#
# Marshalling
#--------------------------------------------------------------------------#
def to_hash
as_hash = { name: name, options: {} }
%i{description title identifier type required value}.each do |field|
val = send(field)
next if val.nil?
as_hash[:options][field] = val
end
as_hash
end
#--------------------------------------------------------------------------#
# Value Type Coercion
#--------------------------------------------------------------------------#

View file

@ -1,6 +1,6 @@
require "forwardable"
require "singleton"
require "inspec/input"
require "inspec/objects/input"
require "inspec/secrets"
require "inspec/exceptions"
require "inspec/plugin/v2"

View file

@ -1,5 +1,5 @@
require "helper"
require "inspec/input"
require "inspec/objects/input"
describe Inspec::Input do
let(:opts) { {} }
@ -32,8 +32,7 @@ describe Inspec::Input do
title: "Best input ever",
description: "important",
type: "Numeric",
required: true
)
required: true)
_(input.to_hash).must_equal({
name: "test_input",
options: {
@ -41,8 +40,8 @@ describe Inspec::Input do
title: "Best input ever",
description: "important",
type: "Numeric",
required: true
}
required: true,
},
})
end
end