lib/bhook/directory.rb in bhook-0.1.6 vs lib/bhook/directory.rb in bhook-0.2.0
- old
+ new
@@ -8,14 +8,13 @@
GIT_DIR = '.git'
MD_EXT = '.md'
sig { params(src_path: Pathname, out_path: Pathname).returns(Bhook::Directory) }
def self.new_root_directory(src_path, out_path)
- self.new(src_path, out_path, Git.open(src_path), Bhook::Config.new(src_path))
+ new(src_path, out_path, Git.open(src_path), Bhook::Config.new(src_path))
end
-
sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void }
def initialize(src_path, out_path, git, config)
@src_path = src_path
@out_path = T.let(out_path.join(src_path.basename), Pathname)
@git = git
@@ -30,13 +29,11 @@
FileUtils.mkdir_p(@out_path)
L.debug("mkdir: #{@out_path}")
@sub_dirs.each { |dir| dir.write!(theme) }
@md_files.map do |file|
Thread.new { file.write!(theme) }
- end.each do |thread|
- thread.join
- end
+ end.each(&:join)
end
sig { returns(T::Array[MdFile]) }
def all_md_files
@md_files + @sub_dirs.map(&:all_md_files).flatten
@@ -51,15 +48,19 @@
sig { void }
def build_next_level_nodes
children = @src_path.children
children.delete(@src_path.join(GIT_DIR))
+ build_nodes(children)
+ end
+ sig { params(children: T::Array[Pathname]).void }
+ def build_nodes(children)
file_threads = []
children.each do |child_path|
if child_path.directory?
@sub_dirs << Directory.new(child_path, @out_path, @git, @config)
- elsif child_path.extname == MD_EXT
+ elsif child_path.extname == MD_EXT && !@config.excluded?(child_path)
file_threads << Thread.new { MdFile.new(child_path, @out_path, @git, @config) }
end
end
file_threads.each { |thread| @md_files << thread.value }
end