Class: Inspec::Resources::Mount

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Mount

Returns a new instance of Mount.



20
21
22
23
24
25
26
# File 'lib/inspec/resources/mount.rb', line 20

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



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

def method_missing(name)
  return nil unless 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.



18
19
20
# File 'lib/inspec/resources/mount.rb', line 18

def file
  @file
end

Instance Method Details

#countObject



32
33
34
35
36
37
# File 'lib/inspec/resources/mount.rb', line 32

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

  mounted.stdout.lines.count
end

#mounted?Boolean

Returns:

  • (Boolean)


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

def mounted?
  file.mounted?
end

#resource_idObject



54
55
56
# File 'lib/inspec/resources/mount.rb', line 54

def resource_id
  @path || "mount"
end

#to_sObject



58
59
60
# File 'lib/inspec/resources/mount.rb', line 58

def to_s
  "Mount #{@path}"
end