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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:, limit:) ⇒ PermissionChecker

Returns a new instance of PermissionChecker.



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

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

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/imap/backup/serializer/permission_checker.rb', line 5

def filename
  @filename
end

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

Instance Method Details

#runObject



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

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