Class: Inspec::Resources::InetdConf

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

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(path = nil) ⇒ InetdConf

Returns a new instance of InetdConf.



22
23
24
25
# File 'lib/resources/inetd_conf.rb', line 22

def initialize(path = nil)
  @conf_path = path || '/etc/inetd.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



33
34
35
# File 'lib/resources/inetd_conf.rb', line 33

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

Instance Method Details

#execObject

overwrite exec to ensure it works with its TODO: this needs to be fixed in RSpec



29
30
31
# File 'lib/resources/inetd_conf.rb', line 29

def exec
  read_params['exec']
end

#read_paramsObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/resources/inetd_conf.rb', line 37

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

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

#to_sObject



50
51
52
# File 'lib/resources/inetd_conf.rb', line 50

def to_s
  'inetd.conf'
end