Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file_tree

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file_tree

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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:

require "rubygems"
require "file_tree"

Now add file tree DSL to your class/module. Depending on the context you may use include or extend:

include FileTree

Now you're ready to create directories and populate them with some files.

Directory with files and subdirectories

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:

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.

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.

SettingDefaultMeaning
content_type:randomDefault content type for files
min_file_size1024minimal size for non-empty files
max_file_size3072maximal 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

FAQs

Package last updated on 12 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc