Class: Inspec::Resources::Mount

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/mount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Mount

Returns a new instance of Mount.



24
25
26
27
28
29
# File 'lib/resources/mount.rb', line 24

def initialize(path)
  @path = path
  @mount_manager = mount_manager_for_os
  return skip_resource 'The `mount` resource is not supported on your OS yet.' if @mount_manager.nil?
  @file = inspec.backend.file(@path)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



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

def method_missing(name)
  return nil if !file.mounted?

  mounted = file.mounted
  return nil if mounted.nil? || mounted.stdout.nil?

  line = mounted.stdout
  # if we got multiple lines, only use the last entry
  line = mounted.stdout.lines.to_a.last if mounted.stdout.lines.count > 1

  # parse content if we are on linux
  @mount_options ||= @mount_manager.parse_mount_options(line)
  @mount_options[name]
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

Instance Method Details

#countObject



35
36
37
38
39
# File 'lib/resources/mount.rb', line 35

def count
  mounted = file.mounted
  return nil if mounted.nil? || mounted.stdout.nil?
  mounted.stdout.lines.count
end

#mounted?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/resources/mount.rb', line 31

def mounted?
  file.mounted?
end

#to_sObject



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

def to_s
  "Mount #{@path}"
end