Class: Inspec::Resources::LimitsConf

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/resources/limits_conf.rb

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(path = nil) ⇒ LimitsConf

Returns a new instance of LimitsConf.



19
20
21
22
# File 'lib/inspec/resources/limits_conf.rb', line 19

def initialize(path = nil)
  @conf_path = path || "/etc/security/limits.conf"
  @content = read_file_content(@conf_path)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



24
25
26
# File 'lib/inspec/resources/limits_conf.rb', line 24

def method_missing(name)
  read_params[name.to_s]
end

Instance Method Details

#read_paramsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inspec/resources/limits_conf.rb', line 28

def read_params
  return @params if defined?(@params)

  # parse the file
  conf = SimpleConfig.new(
    @content,
    assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
    key_values: 3,
    multiple_values: true
  )
  @params = conf.params
end

#resource_idObject



41
42
43
# File 'lib/inspec/resources/limits_conf.rb', line 41

def resource_id
  @conf_path
end

#to_sObject



45
46
47
# File 'lib/inspec/resources/limits_conf.rb', line 45

def to_s
  "limits.conf"
end