Class: Inspec::Resources::PConfig
- Inherits:
-
Object
- Object
- Inspec::Resources::PConfig
show all
- Defined in:
- lib/resources/parse_config.rb
Instance Method Summary
collapse
Constructor Details
#initialize(content = nil, useropts = nil) ⇒ PConfig
Returns a new instance of PConfig.
28
29
30
31
32
33
34
35
36
|
# File 'lib/resources/parse_config.rb', line 28
def initialize(content = nil, useropts = nil)
@opts = {}
@opts = useropts.dup unless useropts.nil?
@files_contents = {}
@params = nil
@content = content
read_content if @content.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
38
39
40
41
|
# File 'lib/resources/parse_config.rb', line 38
def method_missing(name)
@params || read_content
@params[name.to_s]
end
|
Instance Method Details
#parse_file(conf_path) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/resources/parse_config.rb', line 43
def parse_file(conf_path)
@conf_path = conf_path
if !inspec.file(conf_path).file?
return skip_resource "Can't find file \"#{conf_path}\""
end
@content = read_file(conf_path).to_s
if @content.empty? && inspec.file(conf_path).size > 0
return skip_resource "Can't read file \"#{conf_path}\""
end
read_content
end
|
#read_content ⇒ Object
62
63
64
65
66
|
# File 'lib/resources/parse_config.rb', line 62
def read_content
@params = SimpleConfig.new(@content, @opts).params
@content
end
|
#read_file(path) ⇒ Object
58
59
60
|
# File 'lib/resources/parse_config.rb', line 58
def read_file(path)
@files_contents[path] ||= inspec.file(path).content
end
|
#to_s ⇒ Object
68
69
70
|
# File 'lib/resources/parse_config.rb', line 68
def to_s
"Parse Config #{@conf_path}"
end
|