Class: Inspec::Attribute
- Inherits:
-
Object
- Object
- Inspec::Attribute
- Defined in:
- lib/inspec/objects/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #default ⇒ Object
- #description ⇒ Object
-
#initialize(name, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #ruby_var_identifier ⇒ Object
- #title ⇒ Object
- #to_hash ⇒ Object
- #to_ruby ⇒ Object
- #to_s ⇒ Object
-
#value(newvalue = nil) ⇒ Object
implicit call is done by inspec to determine the value of an attribute.
Constructor Details
#initialize(name, options) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 9 10 |
# File 'lib/inspec/objects/attribute.rb', line 6 def initialize(name, ) @name = name @opts = @value = nil end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/inspec/objects/attribute.rb', line 5 def name @name end |
Instance Method Details
#default ⇒ Object
20 21 22 |
# File 'lib/inspec/objects/attribute.rb', line 20 def default @opts[:default] end |
#description ⇒ Object
28 29 30 |
# File 'lib/inspec/objects/attribute.rb', line 28 def description @opts[:description] end |
#ruby_var_identifier ⇒ Object
32 33 34 |
# File 'lib/inspec/objects/attribute.rb', line 32 def ruby_var_identifier 'attr_' + @name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '') end |
#title ⇒ Object
24 25 26 |
# File 'lib/inspec/objects/attribute.rb', line 24 def title @opts[:title] end |
#to_hash ⇒ Object
36 37 38 39 40 41 |
# File 'lib/inspec/objects/attribute.rb', line 36 def to_hash { name: @name, options: @opts, } end |
#to_ruby ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/inspec/objects/attribute.rb', line 43 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 |
#to_s ⇒ Object
52 53 54 |
# File 'lib/inspec/objects/attribute.rb', line 52 def to_s "Attribute #{@name} with #{@value}" end |
#value(newvalue = nil) ⇒ Object
implicit call is done by inspec to determine the value of an attribute
13 14 15 16 17 18 |
# File 'lib/inspec/objects/attribute.rb', line 13 def value(newvalue = nil) unless newvalue.nil? @value = newvalue end @value || default end |