Class: Inspec::Resources::File
- Inherits:
-
Object
- Object
- Inspec::Resources::File
- Defined in:
- lib/resources/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #contain(*_) ⇒ Object
- #executable?(by_owner, by_user) ⇒ Boolean
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #readable?(by_owner, by_user) ⇒ Boolean
- #to_s ⇒ Object
- #writable?(by_owner, by_user) ⇒ Boolean
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
12 13 14 15 |
# File 'lib/resources/file.rb', line 12 def initialize(path) @path = path @file = inspec.backend.file(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/resources/file.rb', line 11 def path @path end |
Instance Method Details
#contain(*_) ⇒ Object
28 29 30 |
# File 'lib/resources/file.rb', line 28 def contain(*_) fail 'Contain is not supported. Please use standard RSpec matchers.' end |
#executable?(by_owner, by_user) ⇒ Boolean
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/resources/file.rb', line 64 def executable?(by_owner, by_user) if inspec.os.unix? by_owner, by_user = check_preconditions(by_owner, by_user) if by_user.nil? m = @file.unix_mode_mask(by_owner, 'x') || fail("#{by_owner} is not a valid unix owner.") return (@file.mode & m) != 0 else return check_user_access(by_user, @path, 'x') end else fail "`file(#{@path}).executable?` is not suported on you OS: #{inspec.os['family']}" end end |
#readable?(by_owner, by_user) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/resources/file.rb', line 32 def readable?(by_owner, by_user) if inspec.os.unix? by_owner, by_user = check_preconditions(by_owner, by_user) if by_user.nil? m = @file.unix_mode_mask(by_owner, 'r') || fail("#{by_owner} is not a valid unix owner.") (@file.mode & m) != 0 else check_user_access(by_user, @path, 'r') end else fail "`file(#{@path}).executable?` is not suported on you OS: #{inspec.os['family']}" end end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/resources/file.rb', line 80 def to_s "File #{@path}" end |
#writable?(by_owner, by_user) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/resources/file.rb', line 48 def writable?(by_owner, by_user) if inspec.os.unix? by_owner, by_user = check_preconditions(by_owner, by_user) if by_user.nil? m = @file.unix_mode_mask(by_owner, 'w') || fail("#{by_owner} is not a valid unix owner.") (@file.mode & m) != 0 else check_user_access(by_user, @path, 'w') end else fail "`file(#{@path}).executable?` is not suported on you OS: #{inspec.os['family']}" end end |