Class: Imap::Backup::Serializer::PermissionChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/serializer/permission_checker.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename:, limit:) ⇒ PermissionChecker

Returns a new instance of PermissionChecker.



7
8
9
10
# File 'lib/imap/backup/serializer/permission_checker.rb', line 7

def initialize(filename:, limit:)
  @filename = filename
  @limit = limit
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/imap/backup/serializer/permission_checker.rb', line 12

def run
  actual = FileMode.new(filename: filename).mode
  return nil if actual.nil?

  mask = ~limit & 0o777
  return if (actual & mask).zero?

  message = format(
    "Permissions on '%<filename>s' " \
    "should be 0%<limit>o, not 0%<actual>o",
    filename: filename, limit: limit, actual: actual
  )
  raise message
end