Class: LimitsConf
- Inherits:
-
Object
- Object
- LimitsConf
- Defined in:
- lib/resources/limits_conf.rb
Overview
Usage:
describe limits_conf do
its('*') { should include ['hard','core','0'] }
end
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ LimitsConf
constructor
A new instance of LimitsConf.
- #method_missing(name) ⇒ Object
- #read_params ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ LimitsConf
Returns a new instance of LimitsConf.
18 19 20 |
# File 'lib/resources/limits_conf.rb', line 18 def initialize(path = nil) @conf_path = path || '/etc/security/limits.conf' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
22 23 24 |
# File 'lib/resources/limits_conf.rb', line 22 def method_missing(name) read_params[name.to_s] end |
Instance Method Details
#read_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/resources/limits_conf.rb', line 26 def read_params return @params if defined?(@params) # read the file file = inspec.file(@conf_path) if !file.file? skip_resource "Can't find file \"#{@conf_path}\"" return @params = {} end content = file.content if content.empty? && file.size > 0 skip_resource "Can't read file \"#{@conf_path}\"" return @params = {} end # parse the file conf = SimpleConfig.new( content, assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/, key_vals: 3, multiple_values: true, ) @params = conf.params end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/resources/limits_conf.rb', line 52 def to_s 'limits.conf' end |