Class: Inspec::Object::Input
- Inherits:
-
Input
- Object
- Input
- Inspec::Object::Input
- Defined in:
- lib/inspec/objects/input.rb
Instance Method Summary collapse
- #ruby_var_identifier ⇒ Object
-
#to_hash ⇒ Object
————————————————————————–# Marshalling ————————————————————————–#.
- #to_ruby ⇒ Object
Instance Method Details
#ruby_var_identifier ⇒ Object
24 25 26 |
# File 'lib/inspec/objects/input.rb', line 24 def ruby_var_identifier identifier || "attr_" + name.downcase.strip.gsub(/\s+/, "-").gsub(/[^\w-]/, "") end |
#to_hash ⇒ Object
————————————————————————–#
Marshalling
————————————————————————–#
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/inspec/objects/input.rb', line 13 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 |
#to_ruby ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/inspec/objects/input.rb', line 28 def to_ruby res = ["#{ruby_var_identifier} = attribute('#{name}',{"] res.push " title: '#{title}'," unless title.to_s.empty? res.push " value: #{value.inspect}," unless value.to_s.empty? # to_ruby may generate code that is to be used by older versions of inspec. # Anything older than 3.4 will not recognize the value: option, so # send the default: option as well. See #3759 res.push " default: #{value.inspect}," unless value.to_s.empty? res.push " description: '#{description}'," unless description.to_s.empty? res.push "})" res.join("\n") end |