Class: Inspec::Resources::InetdConf

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/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.



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

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



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

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



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

def exec
  read_params["exec"]
end

#read_paramsObject



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

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

#resource_idObject



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

def resource_id
  @conf_path || "inetd.conf"
end

#to_sObject



53
54
55
# File 'lib/inspec/resources/inetd_conf.rb', line 53

def to_s
  "inetd.conf"
end