# FileTree FileTree is a ruby library for creating file/directory trees from your code, mostly for testing, where you need to generate file/directory input for your components. The tree gets created somewhere under system's temporary directory (Dir::mktmpdir is used to create a top-level directory). ## Requirements * Ruby 1.9 or greater ## Installation Add this line to your application's Gemfile: gem 'file_tree' And then execute: $ bundle Or install it yourself as: $ gem install file_tree ## Usage Start by adding _file_tree_ module to your project: ```ruby require "rubygems" require "file_tree" ``` Now add file tree DSL to your class/module. Depending on the context you may use _include_ or _extend_: ```ruby include FileTree ``` Now you're ready to create directories and populate them with some files. ### Directory with files and subdirectories ```ruby path = root_dir do dir "dir1-1" do file "file1" file "file2" end dir "dir1-2" dir "dir1-3" do file "file3" file "file4" end file "file5" file "file6" end ``` Now path variable stores path to the directory that you have just created. Files will be of random size and content; zero-length files are possible, as well as binary and text files. ### Content type You can explicitly specify whether your files should have binary or text content: ```ruby root_dir do file "data.bin", :binary file "data.txt", :text file "empty", :empty file "random-1", :random file "random-2" end ``` ("random-2" file will have random content because of the default content type specified in FileTree::Defaults.content_type variable) ### Predefined content There may be times where you want your files to store some predefined content. This is doable. ```ruby root_dir do file "test1.txt", "This is a test!!!" file "test2.txt", "This is only a test!" end ``` ### Configuration The library has a bunch of parameters for you to play with. Messing with them is not necessary - the default values work just fine. All settings are gathered inside FileTree::Defaults module. Setting | Default | Meaning -------------------- | -------------------- | ------------------------------------------------- content_type | :random | Default content type for files min_file_size | 1024 | minimal size for non-empty files max_file_size | 3072 | maximal size for non-empty files ## Contributing 1. Fork it ( https://github.com/[my-github-username]/file_tree/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request