LuckyTemplate
Public interface
Constants
Instance methods
Creates a Folder and yields it, before returning the unlocked Folder
NOTE: Folder is locked when being yielded. See Folder#locked?.
Example:
folder = LuckyTemplate.create_folder do |dir|
dir.locked? # => true
dir.add_file(".keep")
end
folder.locked? # => false
Creates an empty Folder
Example:
folder = LuckyTemplate.create_folder
folder.locked? # => false
Returns a new Snapshot of all files and folders within this folder
Raises Error if folder is locked
NOTE: Does not include file instances in results, only paths
Example:
folder = LuckyTemplate.create_folder do |dir|
dir.add_file(".keep")
dir.add_file("README.md")
dir.add_folder("src") do |src|
src.add_file("hello.cr")
end
end
puts LuckyTemplate.snapshot(folder)
Output:
{
".keep" => LuckyTemplate::FileSystem::File,
"README.md" => LuckyTemplate::FileSystem::File,
"src" => LuckyTemplate::FileSystem::Folder,
"src/hello.cr" => LuckyTemplate::FileSystem::File,
}
Returns true if the folder is valid at the given location
valid - files and folders exist within the given location
NOTE: Does not check contents of files, only the presence of them in the filesystem
Raises ::File::NotFoundError if either a file or folder does not exist
Raises Error if folder is locked
Example:
begin
templates_folder = LuckyTemplate.create_folder
LuckyTemplate.validate!(Path["./templates"], templates_folder) # => true
rescue err : ::File::NotFoundError
puts err.message
end
Returns a Bool if the folder is valid at the given location
valid - files and folders exist within the given location
NOTE: Does not check contents of files, only the presence of them in the filesystem
Example:
templates_folder = LuckyTemplate.create_folder
LuckyTemplate.validate!(Path["./templates"], templates_folder) # => true
Writes the folder to disk at the given location
Raises Error if folder is locked
Raises ::File::AlreadyExistsError if location is not an existing folder
Example:
templates_folder = LuckyTemplate.create_folder
LuckyTemplate.write!(Path["./templates"], templates_folder)