diff --git a/lib/resources/inetd_conf.rb b/lib/resources/inetd_conf.rb index cf4c84dbb..5074a5955 100644 --- a/lib/resources/inetd_conf.rb +++ b/lib/resources/inetd_conf.rb @@ -17,10 +17,6 @@ class InetdConf < Vulcano.resource(1) def initialize(path = nil) @conf_path = path || '/etc/inetd.conf' - @files_contents = {} - @content = nil - @params = nil - read_content end def to_s @@ -28,27 +24,31 @@ class InetdConf < Vulcano.resource(1) end def method_missing(name) - @params || read_content - @params.nil? ? nil : @params[name.to_s] + read_params[name.to_s] end def read_content + return @params unless @params.nil? + # read the file file = vulcano.file(@conf_path) if !file.file? - return skip_resource "Can't find file \"#{@conf_path}\"" + skip_resource "Can't find file \"#{@conf_path}\"" + return @params = {} end - @content = file.content - if @content.empty? && file.size > 0 - return skip_resource "Can't read file \"#{@conf_path}\"" + + content = file.content + if content.empty? && file.size > 0 + skip_resource "Can't read file \"#{@conf_path}\"" + return @params = {} end # parse the file - @params = SimpleConfig.new( - @content, + conf = SimpleConfig.new( + content, assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/, key_vals: 6, multiple_values: false, - ).params - @content + ) + @params = conf.params end end