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


1452
1453
1454
1455
1456
# File 'lib/puppet/settings.rb', line 1452

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


1450
1451
1452
# File 'lib/puppet/settings.rb', line 1450

def name
  @name
end

Instance Method Details

#inspectObject


1484
1485
1486
# File 'lib/puppet/settings.rb', line 1484

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

#set(name, value) ⇒ Object


1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'lib/puppet/settings.rb', line 1461

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

  if !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