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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FolderMaker.



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 Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



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

def base
  @base
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/imap/backup/serializer/folder_maker.rb', line 10

def path
  @path
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



11
12
13
# File 'lib/imap/backup/serializer/folder_maker.rb', line 11

def permissions
  @permissions
end

Instance Method Details

#full_pathObject



31
32
33
# File 'lib/imap/backup/serializer/folder_maker.rb', line 31

def full_path
  File.join(base, path)
end

#runObject



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

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

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