Empty sections hanging around are not useful, so if the last line in a
section is removed then remove the section. If the section still has
comments, then just leave it be.
This does not add the ability to remove sections that do not have
settings to begin with; only allows cleaning a file as puppet makes
changes to it.
This commit adds purging to ini file native types.
Purging will only work for child providers that
implement the method: self.file_path. This is
because collecting all instances of the type (
which is a requirement for purging) is only possible
when the path of the file that is being managed
can be accessed by the class instance (in the
method self.instances.)
This commit adds the following method to the internal
of the ini_file:
- get_settings - has of all settings/values for
a given section
It also adds the following method to the section
class:
- setting_names - list of all setting names in a
section.
These methods are required for the instances method
to be able to list the values for all settings of
each section.
This commit adds support for detecting commented versions of
settings in an existing version of an inifile. If you are
setting a value for a setting that isn't currently set
in the file, but a commented version is found, then we
add the new setting immediately following the commented
version, rather than at the end of the section.
The `save` method was previously relying on some really
specific implementation details of the `section` class
(when the start/end_line would be nil, etc.). This made
the code a bit hard to follow.
This commit introduces a few utility methods in the
`section` class (`is_new_section?`, `is_global?`), and
refactors the `save` method to use them... this makes
the logic a little easier to follow and should hopefully
make it easier to maintain.
This commit adds some cosmetic functionality. The main two
improvements are:
* We'll now pay attention to indentation within existing
sections, and when we write new settings or update
existing ones, we'll match the existing indentation.
* When modifying existing settings, the regex now captures
a greater portion of the original line and preserves it.
Basically, the original whitespacing in the line should
remain intact and only the value should be modified.
This commit makes some minor changes to how we handle removing
settings. In particular, it updates all of the line numbers
of the various 'section' objects to correspond to the new
state of the world based on the removal of a line that appeared
before them.
Also adds one more test related to setting removal.