Class: Inspec::Resources::File
- Inherits:
-
Object
- Object
- Inspec::Resources::File
- Includes:
- MountParser
- Defined in:
- lib/resources/file.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#mount_options ⇒ Object
readonly
Returns the value of attribute mount_options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #contain(*_) ⇒ Object
- #executable?(by_usergroup, by_specific_user) ⇒ Boolean
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #mounted?(expected_options = nil, identical = false) ⇒ Boolean
- #readable?(by_usergroup, by_specific_user) ⇒ Boolean
- #to_s ⇒ Object
- #writable?(by_usergroup, by_specific_user) ⇒ Boolean
Methods included from MountParser
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
24 25 26 27 |
# File 'lib/resources/file.rb', line 24 def initialize(path) @path = path @file = inspec.backend.file(@path) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
23 24 25 |
# File 'lib/resources/file.rb', line 23 def file @file end |
#mount_options ⇒ Object (readonly)
Returns the value of attribute mount_options.
23 24 25 |
# File 'lib/resources/file.rb', line 23 def @mount_options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/resources/file.rb', line 23 def path @path end |
Instance Method Details
#contain(*_) ⇒ Object
40 41 42 |
# File 'lib/resources/file.rb', line 40 def contain(*_) fail 'Contain is not supported. Please use standard RSpec matchers.' end |
#executable?(by_usergroup, by_specific_user) ⇒ Boolean
56 57 58 59 60 |
# File 'lib/resources/file.rb', line 56 def executable?(by_usergroup, by_specific_user) return false unless exist? ('x', by_usergroup, by_specific_user) end |
#mounted?(expected_options = nil, identical = false) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/resources/file.rb', line 62 def mounted?( = nil, identical = false) mounted = file.mounted # return if no additional parameters have been provided return file.mounted? if .nil? # deprecation warning, this functionality will be removed in future version warn "[DEPRECATION] `be_mounted.with and be_mounted.only_with` are deprecated. Please use `mount('#{path}')` instead." # we cannot read mount data on non-Linux systems return nil if !inspec.os.linux? # parse content if we are on linux @mount_options ||= (mounted.stdout, true) if identical # check if the options should be identical @mount_options == else # otherwise compare the selected values @mount_options.contains() end end |
#readable?(by_usergroup, by_specific_user) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/resources/file.rb', line 44 def readable?(by_usergroup, by_specific_user) return false unless exist? ('r', by_usergroup, by_specific_user) end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/resources/file.rb', line 86 def to_s "File #{path}" end |
#writable?(by_usergroup, by_specific_user) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/resources/file.rb', line 50 def writable?(by_usergroup, by_specific_user) return false unless exist? ('w', by_usergroup, by_specific_user) end |