class LuckyTemplate::Folder
- LuckyTemplate::Folder
- Reference
- Object
Overview
A Folder
represents a filesystem directory, but in a virtual form.
Defined in:
lucky_template/folder.crInstance Method Summary
-
#add_file(name : String, content : String, perms : Int16 | Nil = nil) : self
Adds a new file to the folder with content
-
#add_file(path : Path, content : String, perms : Int16 | Nil = nil) : self
Adds a new file to the folder with content
-
#add_file(name : String, klass : Fileable, perms : Int16 | Nil = nil) : self
Adds a new file to the folder with klass implementing
Fileable
interface -
#add_file(path : Path, klass : Fileable, perms : Int16 | Nil = nil) : self
Adds a new file to the folder with klass implementing
Fileable
interface -
#add_file(name : String, perms : Int16 | Nil = nil, &block : FileIO) : self
Adds a new file to the folder yielding an
IO
-
#add_file(path : Path, perms : Int16 | Nil = nil, &block : FileIO) : self
Adds a new file to the folder yielding an
IO
-
#add_file(name : String, perms : Int16 | Nil = nil) : self
Adds a new empty file to the folder
-
#add_file(path : Path, perms : Int16 | Nil = nil) : self
Adds a new empty file to the folder
-
#add_folder(names : Enumerable(String), & : Folder -> ) : self
Adds nested folders, yielding the last one
-
#add_folder(path : Path, & : Folder -> ) : self
Adds nested folders, yielding the last one
-
#add_folder(*names : String, & : Folder -> ) : self
Adds nested folders, yielding the last one
-
#add_folder(names : Enumerable(String)) : self
Adds nested empty folders
-
#add_folder(path : Path) : self
Adds nested empty folders
-
#add_folder(*names : String) : self
Adds nested empty folders
-
#empty? : Bool
Checks if folder has no files or folders
-
#insert_folder(name : String, folder : Folder) : self
Insert an existing folder
-
#locked? : Bool
Checks if folder is locked
Instance Method Detail
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