Class: Puppet::Settings::Values

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/puppet/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, defaults) ⇒ Values

Returns a new instance of Values.



1553
1554
1555
1556
1557
# File 'lib/puppet/settings.rb', line 1553

def initialize(name, defaults)
  @name = name
  @values = {}
  @defaults = defaults
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1551
1552
1553
# File 'lib/puppet/settings.rb', line 1551

def name
  @name
end

Instance Method Details

#inspectObject



1585
1586
1587
# File 'lib/puppet/settings.rb', line 1585

def inspect
  %Q(<#{self.class}:#{object_id} @name="#{@name}" @values="#{@values}">)
end

#set(name, value) ⇒ Object



1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
# File 'lib/puppet/settings.rb', line 1562

def set(name, value)
  default = @defaults[name]

  unless default
    raise ArgumentError, _("Attempt to assign a value to unknown setting %{name}") % { name: name.inspect }
  end

  # This little exception-handling dance ensures that a hook is
  # able to check whether a value for itself has been explicitly
  # set, while still preserving the existing value if the hook
  # throws (as was existing behavior)
  old_value = @values[name]
  @values[name] = value
  begin
    if default.has_hook?
      default.handle(value)
    end
  rescue Exception => e
    @values[name] = old_value
    raise e
  end
end