Class: Imap::Backup::Serializer::Directory

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

Constant Summary collapse

DIRECTORY_PERMISSIONS =
0o700

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, relative) ⇒ Directory

Returns a new instance of Directory.



16
17
18
19
# File 'lib/imap/backup/serializer/directory.rb', line 16

def initialize(path, relative)
  @path = path
  @relative = relative
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/imap/backup/serializer/directory.rb', line 14

def path
  @path
end

#relativeObject (readonly)

Returns the value of attribute relative.



13
14
15
# File 'lib/imap/backup/serializer/directory.rb', line 13

def relative
  @relative
end

Instance Method Details

#ensure_existsObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imap/backup/serializer/directory.rb', line 21

def ensure_exists
  if !File.directory?(full_path)
    Serializer::FolderMaker.new(
      base: path, path: relative, permissions: DIRECTORY_PERMISSIONS
    ).run
  end

  return if OS.windows?
  return if FileMode.new(filename: full_path).mode == DIRECTORY_PERMISSIONS

  FileUtils.chmod DIRECTORY_PERMISSIONS, full_path
end