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.


1470
1471
1472
1473
1474
# File 'lib/puppet/settings.rb', line 1470

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


1468
1469
1470
# File 'lib/puppet/settings.rb', line 1468

def name
  @name
end

Instance Method Details

#inspectObject


1502
1503
1504
# File 'lib/puppet/settings.rb', line 1502

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

#set(name, value) ⇒ Object


1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
# File 'lib/puppet/settings.rb', line 1479

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