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.



1558
1559
1560
1561
1562
# File 'lib/puppet/settings.rb', line 1558

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1556
1557
1558
# File 'lib/puppet/settings.rb', line 1556

def name
  @name
end

Instance Method Details

#inspectObject



1590
1591
1592
# File 'lib/puppet/settings.rb', line 1590

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

#set(name, value) ⇒ Object



1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
# File 'lib/puppet/settings.rb', line 1567

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