lib/bhook/directory.rb in bhook-0.1.0 vs lib/bhook/directory.rb in bhook-0.1.1
- old
+ new
@@ -1,48 +1,54 @@
-# typed: true
+# typed: strict
# frozen_string_literal: true
module Bhook
class Directory
+ extend T::Sig
+
GIT_DIR = '.git'
MD_EXT = '.md'
- attr_reader :sub_dirs, :md_files
-
+ sig { params(src_path: Pathname, git: T.nilable(Git::Base)).void }
def initialize(src_path, git = nil)
@src_path = src_path
@git = git
- @sub_dirs = []
- @md_files = []
+ @sub_dirs = T.let([], T::Array[Directory])
+ @md_files = T.let([], T::Array[MdFile])
build_next_level_nodes
end
+ sig { returns(T::Boolean) }
def root_dir_for_a_commit?
!@git
end
- def write!(out_path)
+ sig { params(out_path: String, theme: Theme).void }
+ def write!(out_path, theme)
dir_path = if root_dir_for_a_commit?
out_path
else
File.join(out_path, @src_path.basename)
end
FileUtils.mkdir_p(dir_path, verbose: true)
- @sub_dirs.each { |dir| dir.write!(dir_path) }
- @md_files.each { |file| file.write!(dir_path) }
+ @sub_dirs.each { |dir| dir.write!(dir_path, theme) }
+ @md_files.each { |file| file.write!(dir_path, theme) }
end
-
+
+ sig { returns(T::Array[MdFile]) }
def all_md_files
@md_files + @sub_dirs.map(&:all_md_files).flatten
end
+ sig { returns(String) }
def to_s
@src_path.to_s
end
private
+ sig { void }
def build_next_level_nodes
if root_dir_for_a_commit?
@git = Git.open(@src_path)
end