LuckyTemplate::Folder
A Folder represents a filesystem directory, but in a virtual form.
Instance methods
Adds a new file to the folder with content
Optionally, provide perms to specify file permissions
Raises Error if name contains invalid path(s)
Examples(s):
add_file("hello.txt", "hello world")
add_file("hello.txt", <<-TEXT)
hello world
TEXT
add_file("hello.txt", "hello world", 0o644)
Adds a new file to the folder with content
Optionally, provide perms to specify file permissions
Raises Error if path contains invalid path(s)
Examples(s):
add_file(Path["./hello.txt"], "hello world")
add_file(Path["./hello.txt"], <<-TEXT)
hello world
TEXT
add_file(Path["./hello.txt"], "hello world", 0o644)
Adds a new file to the folder with klass implementing Fileable interface
Optionally, provide perms to specify file permissions
Raises Error if name contains invalid path(s)
Example(s):
class Hello
include LuckyTemplate::Fileable
def to_file(io : IO) : Nil
io << "hello"
end
end
add_file("hello.txt", Hello.new)
add_file("hello.txt", Hello.new, 0o644)
Adds a new file to the folder with klass implementing Fileable interface
Optionally, provide perms to specify file permissions
Raises Error if path contains invalid path(s)
Example(s):
class Hello
include LuckyTemplate::Fileable
def to_file(io : IO) : Nil
io << "hello"
end
end
add_file(Path["./hello.txt"], Hello.new)
add_file(Path["./hello.txt"], Hello.new, 0o644)
Adds a new file to the folder yielding an IO
Optionally, provide perms to specify file permissions
Raises Error if name contains invalid path(s)
Example(s):
add_file("hello.txt") do |io|
ECR.embed("hello.ecr", io)
end
add_file("hello.txt", 0o644) do |io|
ECR.embed("hello.ecr", io)
end
proc = LuckyTemplate::FileIO.new { |io| ECR.embed("hello.ecr", io) }
add_file("hello.txt", &proc)
add_file("hello.txt", 0o644, &proc)
Adds a new file to the folder yielding an IO
Optionally, provide perms to specify file permissions
Raises Error if path contains invalid path(s)
Example(s):
add_file(Path["./hello.txt"]) do |io|
ECR.embed("hello.ecr", io)
end
add_file(Path["./hello.txt"], 0o644) do |io|
ECR.embed("hello.ecr", io)
end
proc = LuckyTemplate::FileIO.new { |io| ECR.embed("hello.ecr", io) }
add_file(Path["./hello.txt"], &proc)
add_file(Path["./hello.txt"], 0o644, &proc)
Adds a new empty file to the folder
Optionally, provide perms to specify file permissions
Raises Error if name contains invalid path(s)
Example(s):
add_file("hello.txt")
add_file("hello.txt", 0o644)
Adds a new empty file to the folder
Optionally, provide perms to specify file permissions
Raises Error if path contains invalid path(s)
Example:
add_file(Path["./hello.txt"])
add_file(Path["./hello.txt"], 0o644)
Adds nested folders, yielding the last one
Raises Error if names contains invalid folder names
Example:
add_folder(["a", "b", "c"]) do |c|
c.add_file("hello.txt")
end
Produces these folder paths:
a
a/b
a/b/c
a/b/c/hello.txt
Adds nested folders, yielding the last one
Raises Error if path contains invalid folder names
Example:
add_folder(Path["a/b/c"]) do |c|
c.add_file("hello.txt")
end
Produces these folder paths:
a
a/b
a/b/c
a/b/c/hello.txt
Adds nested folders, yielding the last one
Raises Error if names contains invalid folder names
Example:
add_folder("a", "b", "c") do |c|
c.add_file("hello.txt")
end
Produces these folder paths:
a
a/b
a/b/c
a/b/c/hello.txt
Adds nested empty folders
Raises Error if names contains invalid folder names
Example:
add_folder(["a", "b", "c", "d"])
Produces these folder paths:
a
a/b
a/b/c
a/b/c/d
Adds nested empty folders
Raises Error if path contains invalid folder names
Example:
add_folder(Path["a/b/c/d"])
Produces these folder paths:
a
a/b
a/b/c
a/b/c/d
Adds nested empty folders
Raises Error if names contains invalid folder names
Example:
add_folder("a", "b", "c", "d")
Produces these folder paths:
a
a/b
a/b/c
a/b/c/d
Insert an existing folder
Raises Error if one of the following are true:
- existing folder is equal to itself
- existing folder is locked
Example:
another_folder = LuckyTemplate::Folder.new
LuckyTemplate.create_folder do |folder|
folder.insert_folder(another_folder)
end