Class: Inspec::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @name = name
  @opts = options
  @value = nil
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/inspec/objects/attribute.rb', line 5

def name
  @name
end

Instance Method Details

#defaultObject



20
21
22
# File 'lib/inspec/objects/attribute.rb', line 20

def default
  @opts[:default]
end

#to_hashObject



24
25
26
27
28
29
# File 'lib/inspec/objects/attribute.rb', line 24

def to_hash
  {
    name: @name,
    options: @opts,
  }
end

#to_sObject



31
32
33
# File 'lib/inspec/objects/attribute.rb', line 31

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