diff options
author | Karel Brezina <karel.brezina@gmail.com> | 2013-02-15 10:56:44 +0100 |
---|---|---|
committer | Karel Brezina <karel.brezina@gmail.com> | 2013-03-25 11:34:37 +0100 |
commit | 4351d8b9c8dac40f0f733fd7622d655241f113ba (patch) | |
tree | 50020a3b7d7abd357feb7a7eb70666144f3dafd3 /lib/puppet/provider/ini_subsetting/ruby.rb | |
parent | 2008179ebea70d296f65a1809c961951884a7b11 (diff) | |
download | puppet-inifile-4351d8b9c8dac40f0f733fd7622d655241f113ba.tar.gz puppet-inifile-4351d8b9c8dac40f0f733fd7622d655241f113ba.tar.bz2 |
Added 'ini_subsetting' custom resource type
Diffstat (limited to 'lib/puppet/provider/ini_subsetting/ruby.rb')
-rw-r--r-- | lib/puppet/provider/ini_subsetting/ruby.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/puppet/provider/ini_subsetting/ruby.rb b/lib/puppet/provider/ini_subsetting/ruby.rb new file mode 100644 index 0000000..49c0e49 --- /dev/null +++ b/lib/puppet/provider/ini_subsetting/ruby.rb @@ -0,0 +1,70 @@ +require File.expand_path('../../../util/ini_file', __FILE__) +require File.expand_path('../../../util/setting_value', __FILE__) + +Puppet::Type.type(:ini_subsetting).provide(:ruby) do + + def exists? + setting_value.get_subsetting_value(subsetting) + end + + def create + setting_value.add_subsetting(subsetting, resource[:value]) + ini_file.set_value(section, setting, setting_value.get_value) + ini_file.save + @ini_file = nil + @setting_value = nil + end + + def destroy + setting_value.remove_subsetting(subsetting) + ini_file.set_value(section, setting, setting_value.get_value) + ini_file.save + @ini_file = nil + @setting_value = nil + end + + def value + setting_value.get_subsetting_value(subsetting) + end + + def value=(value) + setting_value.add_subsetting(subsetting, resource[:value]) + ini_file.set_value(section, setting, setting_value.get_value) + ini_file.save + end + + def section + resource[:section] + end + + def setting + resource[:setting] + end + + def subsetting + resource[:subsetting] + end + + def subsetting_separator + resource[:subsetting_separator] + end + + def file_path + resource[:path] + end + + def separator + resource[:key_val_separator] || '=' + end + + private + def ini_file + @ini_file ||= Puppet::Util::IniFile.new(file_path, separator) + end + + private + def setting_value + @setting_value ||= Puppet::Util::SettingValue.new(ini_file.get_value(section, setting), subsetting_separator) + end + +end |