Class: Inspec::Object::Input

Inherits:
Input
  • Object
show all
Defined in:
lib/inspec/objects/input.rb

Instance Method Summary collapse

Instance Method Details

#ruby_var_identifierObject



23
24
25
# File 'lib/inspec/objects/input.rb', line 23

def ruby_var_identifier
  identifier || "attr_" + name.downcase.strip.gsub(/\s+/, "-").gsub(/[^\w-]/, "")
end

#to_hashObject

————————————————————————–#

Marshalling

————————————————————————–#



12
13
14
15
16
17
18
19
20
21
# File 'lib/inspec/objects/input.rb', line 12

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_rubyObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/inspec/objects/input.rb', line 27

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