lazy eval limits.conf

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-17 16:37:36 +02:00
parent 6a6c1fd7c8
commit 3508219428

View file

@ -15,10 +15,6 @@ class LimitsConf < Vulcano.resource(1)
def initialize(path = nil)
@conf_path = path || '/etc/security/limits.conf'
@files_contents = {}
@content = nil
@params = nil
read_content
end
def to_s
@ -26,27 +22,32 @@ class LimitsConf < 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
def read_params
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*$/,
key_vals: 3,
multiple_values: true,
).params
@content
)
@params = conf.params
end
end