class Cd::DirEntry

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:29
examples/crystal_dir.cr:30
lib/dir_entry.cr
lib/dir_entry/macros/any.cr
lib/dir_entry/macros/dir.cr

Class Method Summary

Instance Method Summary

Macro Summary

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

def self.cd(*args, &) #

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.


[View source]
def self.tmp(base = "/tmp", &) #

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

[View source]

Instance Method Detail

def [](*args) #

Creates and returns a new underlying AnyEntry instance.

Parameters

  • args : path components under this directory

[View source]
def []?(*args) #

Creates and returns a new underlying AnyEntry instance.

Returns nil if the entry does not exist.

Parameters

  • args : path components under this directory

[View source]
def cd(*args, &) #

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.


[View source]
def cp(dst : String) #

Copies all this directory's contents recursively to the dst path.


[View source]
def cp(dst : Cd) #

Copies all this directory's contents recursively to the dst path.


[View source]
def create #

Creates this directory.


[View source]
def dir(*args) #

Creates a new DirEntry instance under this directory.


[View source]
def each(&) #

Iterates underlying entries.


[View source]
def exists? #

Tests if this directory exists.


[View source]
def glob(*patterns, &) #

Searches and iterates file entries under this directory.

Parameters

  • patterns : search patterns; each pattern is joined under this directory's path.

[View source]
def glob(*patterns) : Array(AnyEntry) #

Searches and returns file entries under this directory.

Parameters

  • patterns : search patterns; each pattern is joined under this directory's path.

[View source]
def path : String #

Returns this directory's path.


[View source]
def remove(recursive = false) #

Removes this directory.


[View source]
def tmp(*args, &) #

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.


[View source]
def tmp(*args) #

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.


[View source]

Macro Detail

macro any(name, type = ::Cd::AnyEntry, method = nil, create = false, mode = nil) #

Defines helper methods for manipulating the given subentry.

See Examples::CrystalDir.


[View source]
macro dir(name, type = ::Cd::DirEntry, method = nil) #

Defines helper methods for manipulating the given subdirectory.

See Examples::CrystalDir.


[View source]