extend the attributes object with helper methods

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
Christoph Hartmann 2016-10-14 17:08:49 +02:00
parent 41d31163ac
commit c67ff8b4a2

View file

@ -21,6 +21,18 @@ module Inspec
@opts[:default]
end
def title
@opts[:title]
end
def description
@opts[:description]
end
def ruby_var_identifier
'attr_' + @name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '')
end
def to_hash
{
name: @name,
@ -28,6 +40,15 @@ module Inspec
}
end
def to_ruby
res = ["#{ruby_var_identifier} = attribute('#{@name}',{"]
res.push " title: '#{title}'," unless title.to_s.empty?
res.push " default: '#{default}'," unless default.to_s.empty?
res.push " description: '#{description}'," unless description.to_s.empty?
res.push '})'
res.join("\n")
end
def to_s
"Attribute #{@name} with #{@value}"
end