From a37f264c4d61a73fad28d8799f8299a5fc1f0ee0 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Mon, 22 Jun 2015 14:32:42 -0700 Subject: [PATCH] Remove unnecessary hocon require, add write_conf method Prior to this commit we had a separate config_saver module for saving the hocon config to disk. This module was requiring the hocon gem without Puppet feature protection. This was causing requirement issues on the Puppet Server side, where the hocon gem is not typically installed. This commit moves the code from config saver into the main hocon provider, as the method write_conf. This removes the unnecessary require, and cleans up the unnecessary config_saver module. --- lib/puppet/provider/hocon_setting/ruby.rb | 15 ++++++++++----- lib/puppet/util/config_saver.rb | 15 --------------- 2 files changed, 10 insertions(+), 20 deletions(-) delete mode 100644 lib/puppet/util/config_saver.rb diff --git a/lib/puppet/provider/hocon_setting/ruby.rb b/lib/puppet/provider/hocon_setting/ruby.rb index 6fa546a..872820d 100644 --- a/lib/puppet/provider/hocon_setting/ruby.rb +++ b/lib/puppet/provider/hocon_setting/ruby.rb @@ -5,8 +5,6 @@ require 'hocon/config_value_factory' end -require File.expand_path('../../../util/config_saver', __FILE__) - Puppet::Type.type(:hocon_setting).provide(:ruby) do def self.namevar(section_name, setting) "#{setting}" @@ -18,13 +16,13 @@ def exists? def create conf_file_modified = set_value(resource[:value]) - Puppet::Util::ConfigSaver.save(resource[:path], conf_file_modified) + write_conf(conf_file_modified) @conf_file = nil end def destroy conf_file_modified = conf_file.remove_value(setting) - Puppet::Util::ConfigSaver.save(resource[:path], conf_file_modified) + write_conf(conf_file_modified) @conf_file = nil end @@ -50,7 +48,7 @@ def value def value=(new_value) conf_file_modified = set_value(new_value) - Puppet::Util::ConfigSaver.save(resource[:path], conf_file_modified) + write_conf(conf_file_modified) @conf_file = nil end @@ -70,6 +68,13 @@ def conf_file @conf_file ||= Hocon::Parser::ConfigDocumentFactory.parse_file(file_path) end + def write_conf(conf) + File.open(file_path, 'w+') do |fh| + config_string = conf.render + fh.puts(config_string) + end + end + def conf_object if @conf_file.nil? && (not File.exist?(file_path)) File.new(file_path, "w") diff --git a/lib/puppet/util/config_saver.rb b/lib/puppet/util/config_saver.rb deleted file mode 100644 index a2ec9c9..0000000 --- a/lib/puppet/util/config_saver.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'hocon' -require 'hocon/config_render_options' - -module Puppet - module Util - class ConfigSaver - def self.save(path, conf) - File.open(path, 'w+') do |fh| - config_string = conf.render - fh.puts(config_string) - end - end - end - end -end \ No newline at end of file