mirror of
https://github.com/inspec/inspec
synced 2024-11-22 20:53:11 +00:00
extend the attributes object with helper methods
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
parent
41d31163ac
commit
c67ff8b4a2
1 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue