Skip to content

🐵 Monkey Patch for tmp dir creation on Crystal standard library

License

Notifications You must be signed in to change notification settings

Green-Edge/tmpdir.cr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmpdir.cr

Temporary Monkey Patch solution to create temporary directories with Crystal.

Forked from marceloboeira/tmpdir.cr to address small issues with recent releases of Crystal.

Installation

Add this to your application's shard.yml:

dependencies:
  tmpdir:
    github: Green-Edge/tmpdir.cr

Usage

Require the library, then...

Without prefix:

require "tmpdir"

puts Dir.mktmpdir
# => /tmp/c.a39bF4

With prefix:

require "tmpdir"

puts Dir.mktmpdir("foo")
# => /tmp/foo.a39bF4

Within a block:

require "tmpdir"

Dir.mktmpdir("foo") do |tmp_dir|
  puts tmp_dir
  # => /tmp/foo.a39bF4
end

# tmp_dir does not exists anymore

The solution uses the LibC.mkdtemp bind. The mkdtemp function creates a directory with a unique name. If it succeeds, it overwrites template with the name of the directory, and returns template. As with mktemp and mkstemp, template should be a string ending with ‘XXXXXX’.

Reference:

Testing

$ crystal spec

About

🐵 Monkey Patch for tmp dir creation on Crystal standard library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Crystal 100.0%