Comparisons and transformation between trees of files and JSON blobs
The "JSON blobs" that are supported are not unlimited in structure, but must define:
- hashes, where are the values are either {hashes where the values are all scalars} or {arrays of hashes where the values are all scalars}
- or arrays of hashes as described above.
Add this line to your application's Gemfile:
gem 'treet'
And then execute:
$ bundle
Or install it yourself as:
$ gem install treet
treet expand [path] [jsonfile]
treet explode [jsonfile] [rootdir]
treet import [rootdir] [xrefkey]
require 'treet'
hash = Treet::Hash.new(jsonfile)
repo = Treet::Repo.new(directory)
farm = Treet::Farm.new(rootdir, :xref => 'label')
hash = repo.to_hash
repo = hash.to_repo(root)
hash = farm.export
Treet.init(jsonfile, root) # when jsonfile contains an array which is exploded to multiple files
A repo is a directory that contains other files & directories. Any text files in this tree structure must contain JSON-formatted data.
A farm is a directory containing one or more repos. When a farm is exported to JSON, each record is augmented with an xref value that contains the root filename of that repo.
For example:
farm = Treet::Farm.new(rootdir, :xref => 'keycode')
puts farm.export
should produce something like:
{
"subdir1": {
"field": "value"
},
"subdir2": {
"field": "value",
"field2": "value2"
},
"xref": {
"keycode": "repo-dir-name"
}
}
All the nodes at the top level are mapped to subdirectories.
At the second level, arrays elements are converted to individual subdirectories. Subdirectories are named with unique digest values computed from the data contents. This means that duplicate entries are not allowed.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- why is caching built into treet farm? The data on disk could change. Caching doesn't belong here.
- Enforce limitation on structure depth (top-level elements can contain flat hashes or arrays, nothing else)
- refac: move diff stuff from hash.rb to Treet::Diff class, to encapsulate the structure of a diff (array of arrays); create methods for hunting for special stuff in a diff
- Check all exceptions for explicit classes