Class: Inspec::Resources::LoginDefs

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

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(path = nil) ⇒ LoginDefs

Returns a new instance of LoginDefs.



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

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



36
37
38
# File 'lib/inspec/resources/login_defs.rb', line 36

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

Instance Method Details

#read_paramsObject



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

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

#resource_idObject



52
53
54
# File 'lib/inspec/resources/login_defs.rb', line 52

def resource_id
  @conf_path
end

#to_sObject



56
57
58
# File 'lib/inspec/resources/login_defs.rb', line 56

def to_s
  "login.defs"
end