Class: Inspec::Resources::LoginDef

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

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(path = nil) ⇒ LoginDef

Returns a new instance of LoginDef.



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

def initialize(path = nil)
  @conf_path = path || '/etc/login.defs'
  @content = read_file_content(@conf_path)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



37
38
39
# File 'lib/resources/login_def.rb', line 37

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

Instance Method Details

#read_paramsObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/resources/login_def.rb', line 41

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

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

#to_sObject



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

def to_s
  'login.defs'
end