Class: Algerb::FilesBuilder

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/algerb/files_builder.rb

Constant Summary collapse

FILE_PATTERN =
%r{^([a-z0-9\_\.])/?}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#file_to_class, #indentation, #remove_dir, #remove_ext, #split_dir_and_file, #split_path_as_head_and_tail

Constructor Details

#initializeFilesBuilder

Returns a new instance of FilesBuilder.



8
9
10
# File 'lib/algerb/files_builder.rb', line 8

def initialize
  @files = Algerb::Files.new
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



4
5
6
# File 'lib/algerb/files_builder.rb', line 4

def files
  @files
end

Instance Method Details

#add(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/algerb/files_builder.rb', line 12

def add(path)
  dir, file = split_dir_and_file(path)
  if dir
    mkdir_p(dir)
    files.find_by_path(dir).add(Algerb::File.new(file))
  else
    files.add(Algerb::File.new(file))
  end
  self
end

#mkdir_p(path) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/algerb/files_builder.rb', line 23

def mkdir_p(path)
  target = files
  while path
    dir, path = split_path_as_head_and_tail(path)
    target.add(Algerb::Files.new(dir))
    target = target.find_by_path(dir)
  end
end