Class: Thunderbird::Subdirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/thunderbird/subdirectory.rb

Overview

Represents a subdirectory containing folders

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, path:) ⇒ Subdirectory

Returns a new instance of Subdirectory.



13
14
15
16
# File 'lib/thunderbird/subdirectory.rb', line 13

def initialize(root:, path:)
  @root = root
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

‘path` is the UI path, it doesn’t have the ‘.sbd’ extensions that are present in the real, file system path



10
11
12
# File 'lib/thunderbird/subdirectory.rb', line 10

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



11
12
13
# File 'lib/thunderbird/subdirectory.rb', line 11

def root
  @root
end

Instance Method Details

#full_pathObject

subdirectory relative path is ‘Foo.sbd/Bar.sbd/Baz.sbd’



36
37
38
39
# File 'lib/thunderbird/subdirectory.rb', line 36

def full_path
  relative_path = File.join(subdirectories)
  File.join(root, relative_path)
end

#set_upObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/thunderbird/subdirectory.rb', line 18

def set_up
  raise "Cannot create a subdirectory without a path" if !sub_directory?

  if sub_sub_directory?
    parent_ok = parent.set_up
    return false if !parent_ok
  end

  ok = check
  return false if !ok

  FileUtils.mkdir_p full_path
  placeholder.touch

  true
end