class Inspec::Resources::NtpConf

Public Class Methods

new(path = nil) click to toggle source
# File lib/inspec/resources/ntp_conf.rb, line 20
def initialize(path = nil)
  @conf_path = path || "/etc/ntp.conf"
  @content = read_file_content(@conf_path)
end

Public Instance Methods

method_missing(name) click to toggle source
# File lib/inspec/resources/ntp_conf.rb, line 25
def method_missing(name)
  param = read_params[name.to_s]
  # extract first value if we have only one value in array
  return param[0] if param.is_a?(Array) && (param.length == 1)

  param
end
to_s() click to toggle source
# File lib/inspec/resources/ntp_conf.rb, line 33
def to_s
  "ntp.conf"
end

Private Instance Methods

read_params() click to toggle source
# File lib/inspec/resources/ntp_conf.rb, line 39
def read_params
  return @params if defined?(@params)

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