Usefull helper to build all paths in one hash to local files and folders.
- Quickstart
- Setup
- Methods
- Tree Structure
- Console Output
- Contributing
- Limitations
- License
- Code of Conduct
- Support my Work
require 'local_path_builder'
struct = LocalPathBuilder.helper()
LocalPathBuilder.generate( struct, :both )
Add this line to your application's Gemfile:
gem 'local_path_builder'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install local_path_builder
On Rubygems:
.helper()
require 'local_path_builder'
hash = LocalPathBuilder.helper()
# => { path:
.generate( struct[:path], key )
require 'local_path_builder'
hash = LocalPathBuilder.generate(
path_tree,
console_mode,
salt
)
Input
Type | Required | Description | Example | Description |
---|---|---|---|---|
path tree | Hash |
Yes | please refer path structure
|
Define path structure |
console mode | Symbol |
Yes | :hash |
Set console output mode. Use :silent , :hash , :path or :both
|
salt | String |
No | '1624262108' |
Use salt to create unique filenames. |
Return
Hash (See also Console Output)
A struct input is required to generate all paths. Use the following as reference to design your own tree
Example Tree
{
root: './',
name: '1',
children: {
entry: {
name: '0-entry',
files: {
tsv: {
name: 'rest-{{SALT}}.tsv',
}
}
},
converted: {
name: '1-converted',
children: {
json_folder: {
name: '0-json',
files: {
json: {
name: 'data-{{SALT}}.json',
}
}
},
tsv_folder: {
name: '0-tsv',
files: {
tsv: {
name: 'data-{{SALT}}.json',
}
}
}
},
files: {
json: {
name: 'data-{{SALT}}.json',
}
}
}
}
}
LocalPathBuiler.helper()
will give you the same output.
The second parameter of the .generate()
function expects a symbol. you can choose between :silent
, :hash
, path
and both
.
:silent
Console stays silent.
:hash
Console log all variables which are available.
LocalPathBuilder.generate( struct, :hash )
TREE OVERVIEW
hash[:path][:full]
┗━ hash[:path][:children][:entry][:full]
┗━ hash[:path][:children][:entry][:files][:tsv][:full]
┗━ hash[:path][:children][:converted][:full]
┗━ hash[:path][:children][:converted][:files][:json][:full]
┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]
:path
Console log all path which were created.
LocalPathBuilder.generate( struct, :path )
TREE OVERVIEW
./1/
./1/0-entry/
./1/0-entry/rest-1624263104.tsv
./1/1-converted/
./1/1-converted/data-1624263104.json
./1/1-converted/0-json/
./1/1-converted/0-json/data-1624263104.json
./1/1-converted/0-tsv/
./1/1-converted/0-tsv/data-1624263104.json
:both
Console log hash variable and the corresponding file path.
LocalPathBuilder.generate( struct, :both )
TREE OVERVIEW
hash[:path][:full]
./1/
┗━ hash[:path][:children][:entry][:full]
./1/0-entry/
┗━ hash[:path][:children][:entry][:files][:tsv][:full]
./1/0-entry/rest-1624263104.tsv
┗━ hash[:path][:children][:converted][:full]
./1/1-converted/
┗━ hash[:path][:children][:converted][:files][:json][:full]
./1/1-converted/data-1624263104.json
┗━ hash[:path][:children][:converted][:children][:json_folder][:full]
./1/1-converted/0-json/
┗━ hash[:path][:children][:converted][:children][:json_folder][:files][:json][:full]
./1/1-converted/0-json/data-1624263104.json
┗━ hash[:path][:children][:converted][:children][:tsv_folder][:full]
./1/1-converted/0-tsv/
┗━ hash[:path][:children][:converted][:children][:tsv_folder][:files][:tsv][:full]
./1/1-converted/0-tsv/data-1624263104.json
Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/statosio-for-wordpress. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
- Only three levels of folders are supported
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the LocalPathBuilder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Please ⭐️ star this Project, every ⭐️ star makes us very happy!