class Cd::DirEntry
- Cd::DirEntry
- Reference
- Object
Overview
An example class for EntryDir.dir
and EntryDir.any
.
class CrystalDir < Cd::EntryDir
class SpecDir < Cd::EntryDir
def files
glob("**/*_spec.cr")
end
end
dir "spec", SpecDir
any "shard.yml"
def shard
YAML.parse(shard_yml.read)
end
def version
shard["version"].to_s
end
end
Included Modules
Direct Known Subclasses
Defined in:
examples/crystal_dir.cr:29examples/crystal_dir.cr:30
lib/dir_entry.cr
lib/dir_entry/macros/any.cr
lib/dir_entry/macros/dir.cr
Class Method Summary
-
.cd(*args, &)
Changes the current directory.
-
.tmp(base = "/tmp", &)
Changes the current directory into a new temporary directory.
Instance Method Summary
-
#[](*args)
Creates and returns a new underlying
AnyEntry
instance. -
#[]?(*args)
Creates and returns a new underlying
AnyEntry
instance. -
#cd(*args, &)
Changes the current directory.
-
#cp(dst : String)
Copies all this directory's contents recursively to the dst path.
-
#cp(dst : Cd)
Copies all this directory's contents recursively to the dst path.
-
#create
Creates this directory.
-
#dir(*args)
Creates a new
DirEntry
instance under this directory. -
#each(&)
Iterates underlying entries.
-
#exists?
Tests if this directory exists.
-
#glob(*patterns, &)
Searches and iterates file entries under this directory.
-
#glob(*patterns) : Array(AnyEntry)
Searches and returns file entries under this directory.
-
#path : String
Returns this directory's path.
-
#remove(recursive = false)
Removes this directory.
-
#tmp(*args, &)
Changes the current directory into a new temporary directory.
-
#tmp(*args)
Creates and returns a new temporary directory.
Macro Summary
-
any(name, type = ::Cd::AnyEntry, method = nil, create = false, mode = nil)
Defines helper methods for manipulating the given subentry.
-
dir(name, type = ::Cd::DirEntry, method = nil)
Defines helper methods for manipulating the given subdirectory.
Instance methods inherited from module Cd::AsAnyEntry
append(text)
append,
basedir
basedir,
basename(suffix : String | Nil = nil)
basename,
chmod(mode : Int)
chmod,
cp(dst : String)cp(dst : AsAnyEntry) cp, directory?(*args) directory?, dirname dirname, executable?(*args) executable?, exists? exists?, file?(*args) file?, join(*args) join, read read, real_path real_path, remove remove, symlink? symlink?, to_dir to_dir, to_s(io : IO) to_s, touch(mode : Int | Nil = nil) touch, write(text, mode : Int | Nil = nil) write
Class Method Detail
Changes the current directory.
This method creates a new DirEntry
instance with a path that joins the args path components.
If the joined path is relative, the path is expanded under the current directory's path.
The block is called with the new instance.
The current directory is restored after the block returns.
Changes the current directory into a new temporary directory.
This method creates a new DirEntry
instance with the new temporary directory's path.
The block is called with the new instance.
The current directory is restored after the block returns.
The temporary directory is removed after the block returns.
Parameters
- base : a directory path that the temporary directory is created in
Instance Method Detail
Creates and returns a new underlying AnyEntry
instance.
Parameters
- args : path components under this directory
Creates and returns a new underlying AnyEntry
instance.
Returns nil if the entry does not exist.
Parameters
- args : path components under this directory
Changes the current directory.
This method creates a new DirEntry
instance with a path that joins this directory's path and the args path components.
The block is called with the new instance.
The current directory is restored after the block returns.
Searches and iterates file entries under this directory.
Parameters
- patterns : search patterns; each pattern is joined under this directory's path.
Searches and returns file entries under this directory.
Parameters
- patterns : search patterns; each pattern is joined under this directory's path.
Changes the current directory into a new temporary directory.
This method creates a temporary directory, using C mkdtemp, under this directory's path and a new DirEntry
instance with a path that joins the temporary directory's path and the args path components.
The block is called with tthe new instance.
The temporary directory is removed after the block returns.
Creates and returns a new temporary directory.
This method creates a new DirEntry
instance with a path that joins the new temporary directory's path and the args path components.
The temporary directory is created under this directory.
If this instance is created by the DirEntry#cd
method, the temporary directory is removed after the cd method returns.
Otherwise, the temporary directory is never automatically removed.
Macro Detail
Defines helper methods for manipulating the given subentry.
See Examples::CrystalDir
.
Defines helper methods for manipulating the given subdirectory.
See Examples::CrystalDir
.