Skip to content

About

ActiveRecord-like transaction block for files in a directory

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

File transaction

Copy a directory to a temp directory temporarily to perform mutations, to then copy it back.

If any exceptions are raised within the block, the changes will not be copied back.

Usage

# Will create `a`, `b`, `c` in `/my/path`
File.transaction("/my/path") do |dir|
  FileUtils.touch(dir.join("a"))
  FileUtils.touch(dir.join("b"))
  system("echo 'c' >#{dir}/c")
end

# Will make no changes to `/my/path`
File.transaction("/my/path") do |dir|
  FileUtils.touch(dir.join("a"))
  FileUtils.touch(dir.join("b"))
  system("echo 'c' >#{dir}/c")
  raise "Any error" # <-------------
end

About

ActiveRecord-like transaction block for files in a directory

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages