Class: Imap::Backup::Serializer::FolderMaker

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

Overview

Creates directories

Instance Method Summary collapse

Constructor Details

#initialize(base:, path:, permissions:) ⇒ FolderMaker

Returns a new instance of FolderMaker.

Parameters:

  • base (String)

    The base directory of the account

  • path (String)

    The path to the folder, relative to the base

  • permissions (Integer)

    The permissions to set on the folder



13
14
15
16
17
# File 'lib/imap/backup/serializer/folder_maker.rb', line 13

def initialize(base:, path:, permissions:)
  @base = base
  @path = path
  @permissions = permissions
end

Instance Method Details

#runObject

Creates the directory and any missing parent directories, ensuring the desired permissions.



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

def run
  parts = path.split("/")
  return if parts.empty?

  FileUtils.mkdir_p(full_path)
  full = base
  parts.each do |part|
    full = File.join(full, part)
    FileUtils.chmod permissions, full
  end
end