Skip to content

Commit

Permalink
Merge pull request #16 from highb/fix/remove_unnecessary_hocon_require
Browse files Browse the repository at this point in the history
Remove unnecessary hocon require, add write_conf method
  • Loading branch information
jpinsonault committed Jun 22, 2015
2 parents 4ca6991 + a37f264 commit 2a24856
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
15 changes: 10 additions & 5 deletions lib/puppet/provider/hocon_setting/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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")
Expand Down
15 changes: 0 additions & 15 deletions lib/puppet/util/config_saver.rb

This file was deleted.

0 comments on commit 2a24856

Please sign in to comment.