forester 4.3.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +16 -1
- data/.travis.yml +4 -5
- data/CHANGELOG.md +14 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +1 -1
- data/{LICENSE → LICENSE.txt} +5 -5
- data/README.md +60 -24
- data/Rakefile +4 -4
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/forester.gemspec +28 -20
- data/lib/forester.rb +13 -11
- data/lib/forester/tree_factory.rb +18 -49
- data/lib/forester/tree_node.rb +68 -80
- data/lib/forester/tree_node_ext/iterators.rb +57 -0
- data/lib/forester/tree_node_ext/mutators.rb +36 -43
- data/lib/forester/tree_node_ext/serializers.rb +48 -0
- data/lib/forester/tree_node_ext/validators.rb +21 -24
- data/lib/forester/version.rb +1 -15
- metadata +78 -50
- data/lib/forester/node_content/base.rb +0 -9
- data/lib/forester/node_content/dictionary.rb +0 -91
- data/lib/forester/node_content/factory.rb +0 -25
- data/lib/forester/node_content/list.rb +0 -31
- data/lib/forester/tree_node_ext/aggregators.rb +0 -101
- data/lib/forester/tree_node_ext/views.rb +0 -34
- data/test/minitest_helper.rb +0 -41
- data/test/test_ad_hoc_tree.rb +0 -48
- data/test/test_aggregators.rb +0 -105
- data/test/test_mutators.rb +0 -97
- data/test/test_tree_factory.rb +0 -30
- data/test/test_tree_node.rb +0 -44
- data/test/test_validators.rb +0 -240
- data/test/test_views.rb +0 -22
- data/test/trees/simple_tree.yml +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15d624a03bf22e3aa31e6b4d95188d206e408157
|
4
|
+
data.tar.gz: 531f71e74b49b45a6993136e8c184ac1d69fca56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 505f8d2c8240652c9abdfc8bdfae4375001c7741f68afd576a3f906533009ea45b73f885a6800aff6b50bbba1241a88855644cd300222f9c3041640253661ec7
|
7
|
+
data.tar.gz: d8dfd6091c239b0bdcab3f3e469670555c98209044285c895d7b42d09dd598fb464ee68716ad9037f2034fa453f8cf478fd50234d1955153786a8e27f9394b9a
|
data/.gitignore
CHANGED
@@ -5,14 +5,29 @@
|
|
5
5
|
/InstalledFiles
|
6
6
|
/pkg/
|
7
7
|
/spec/reports/
|
8
|
+
/spec/examples.txt
|
8
9
|
/test/tmp/
|
9
10
|
/test/version_tmp/
|
10
11
|
/tmp/
|
11
12
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
12
16
|
## Specific to RubyMotion:
|
13
17
|
.dat*
|
14
18
|
.repl_history
|
15
19
|
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
16
31
|
|
17
32
|
## Documentation cache and generated files:
|
18
33
|
/.yardoc/
|
@@ -20,7 +35,7 @@ build/
|
|
20
35
|
/doc/
|
21
36
|
/rdoc/
|
22
37
|
|
23
|
-
## Environment
|
38
|
+
## Environment normalization:
|
24
39
|
/.bundle/
|
25
40
|
/vendor/bundle
|
26
41
|
/lib/bundler/man/
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Forester Changelog
|
2
|
+
|
3
|
+
All notable changes to this project since version 5 will be documented in this file. This project adheres to [Semantic Versioning][Semver].
|
4
|
+
|
5
|
+
## [Unreleased]
|
6
|
+
|
7
|
+
* Your contribution here!
|
8
|
+
|
9
|
+
## 5.0.0 (2017-08-06)
|
10
|
+
|
11
|
+
* Version 5 release
|
12
|
+
|
13
|
+
[Semver]: http://semver.org
|
14
|
+
[Unreleased]: https://github.com/eugeniobruno/forester/compare/v5.0.0...HEAD
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at eugeniobruno@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2017 Eugenio Bruno
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
copies or substantial portions of the Software.
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
SOFTWARE.
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,49 +1,85 @@
|
|
1
1
|
# Forester
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/forester)
|
4
|
+
[](https://travis-ci.org/eugeniobruno/forester)
|
5
|
+
[](https://coveralls.io/github/eugeniobruno/forester?branch=master)
|
6
|
+
[](https://codeclimate.com/github/eugeniobruno/forester)
|
7
|
+
[](https://gemnasium.com/eugeniobruno/forester)
|
4
8
|
|
5
|
-
|
9
|
+
Forester's functionality is a superset of [RubyTree](https://github.com/evolve75/RubyTree)'s that further facilitates the work with tree data structures at the right level of abstraction.
|
6
10
|
|
7
|
-
##
|
11
|
+
## Installation
|
8
12
|
|
9
|
-
|
13
|
+
Add this line to your application's Gemfile:
|
10
14
|
|
11
|
-
|
15
|
+
gem 'forester'
|
12
16
|
|
13
|
-
|
17
|
+
And then execute:
|
14
18
|
|
15
|
-
|
19
|
+
$ bundle
|
16
20
|
|
17
|
-
|
21
|
+
Or install it yourself as:
|
18
22
|
|
19
|
-
|
23
|
+
$ gem install forester
|
20
24
|
|
21
|
-
|
25
|
+
## Usage
|
22
26
|
|
23
|
-
|
27
|
+
Here is a simple example:
|
24
28
|
|
25
|
-
|
29
|
+
```ruby
|
30
|
+
serialized_tree = {
|
31
|
+
label: 'anything',
|
32
|
+
count: 0,
|
33
|
+
children: [
|
34
|
+
{
|
35
|
+
label: 'first child',
|
36
|
+
count: 1,
|
37
|
+
children: [
|
38
|
+
{
|
39
|
+
label: 'first grandchild',
|
40
|
+
count: 3
|
41
|
+
}
|
42
|
+
]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
label: 'second child',
|
46
|
+
count: 2
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
26
50
|
|
27
|
-
|
51
|
+
# Any node can have any set of fields
|
28
52
|
|
29
|
-
|
53
|
+
tree = Forester.tree_factory.from_root_hash(serialized_tree, children_key: :children)
|
30
54
|
|
31
|
-
|
55
|
+
all_counts = tree.each_node(traversal: :breadth_first).map { |n| n.get(:count) }
|
56
|
+
# [0, 1, 2, 3]
|
32
57
|
|
33
|
-
|
58
|
+
tree.add_child_content(label: 'third child')
|
34
59
|
|
35
|
-
|
60
|
+
tree.validate_uniqueness_of_field(:label)
|
61
|
+
# { is_valid: true, repeated: {}, failures: {} }
|
36
62
|
|
37
|
-
|
63
|
+
tree.as_root_hash
|
64
|
+
# a hash with the same structure as serialized_tree
|
65
|
+
```
|
38
66
|
|
39
|
-
|
67
|
+
The full set of utilities are covered with unit tests, which also serve as usage examples.
|
68
|
+
|
69
|
+
|
70
|
+
## Development
|
40
71
|
|
41
|
-
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
42
75
|
|
43
76
|
## Contributing
|
44
77
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eugeniobruno/forester. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
79
|
+
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
84
|
+
|
85
|
+
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
1
2
|
require 'rake/testtask'
|
2
3
|
|
3
|
-
Rake::TestTask.new do |t|
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
4
5
|
t.libs << 'test'
|
5
|
-
t.
|
6
|
+
t.test_files = FileList['test/**/test_*.rb']
|
6
7
|
end
|
7
8
|
|
8
|
-
desc "Run tests"
|
9
9
|
task default: :test
|
10
10
|
|
11
11
|
desc 'Start a REPL session'
|
@@ -14,4 +14,4 @@ task :console do
|
|
14
14
|
require 'pry'
|
15
15
|
ARGV.clear
|
16
16
|
Pry.start
|
17
|
-
end
|
17
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'forester'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/forester.gemspec
CHANGED
@@ -1,30 +1,38 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'forester/version'
|
5
6
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
s.authors = "Eugenio Bruno"
|
13
|
-
s.email = 'eugeniobruno@gmail.com'
|
14
|
-
s.homepage = 'https://github.com/eugeniobruno/forester'
|
15
|
-
s.license = 'MIT'
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'forester'
|
9
|
+
spec.version = Forester::VERSION
|
10
|
+
spec.date = '2017-08-06'
|
11
|
+
spec.authors = ['Eugenio Bruno']
|
12
|
+
spec.email = ['eugeniobruno@gmail.com']
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
spec.summary = 'Forester is a library to work with tree data structures.'
|
15
|
+
spec.homepage = 'https://github.com/eugeniobruno/forester'
|
16
|
+
spec.license = 'MIT'
|
20
17
|
|
21
|
-
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
spec.extra_rdoc_files = %w[LICENSE.txt README.md CODE_OF_CONDUCT.md CHANGELOG.md]
|
22
26
|
|
23
|
-
|
27
|
+
spec.required_ruby_version = '>= 2.0.0'
|
24
28
|
|
25
|
-
|
26
|
-
s.add_development_dependency 'minitest', '~> 5.10'
|
27
|
-
s.add_development_dependency 'simplecov', '~> 0.14'
|
28
|
-
s.add_development_dependency 'pry-byebug', '~> 3.4'
|
29
|
+
spec.add_runtime_dependency 'rubytree', '= 0.9.7'
|
29
30
|
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
34
|
+
spec.add_development_dependency 'minitest-bender', '~> 0.0'
|
35
|
+
spec.add_development_dependency 'simplecov', '~> 0.14'
|
36
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
37
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.4'
|
30
38
|
end
|
data/lib/forester.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'forester/version'
|
2
|
+
|
3
3
|
require 'securerandom'
|
4
|
-
require 'yaml'
|
5
4
|
|
6
|
-
require '
|
7
|
-
require 'forester/tree_node_ext/validators'
|
8
|
-
require 'forester/tree_node_ext/mutators'
|
9
|
-
require 'forester/tree_node_ext/views'
|
5
|
+
require 'tree'
|
10
6
|
|
11
|
-
require 'forester/
|
12
|
-
require 'forester/
|
13
|
-
require 'forester/
|
14
|
-
require 'forester/
|
7
|
+
require 'forester/tree_node_ext/iterators'
|
8
|
+
require 'forester/tree_node_ext/mutators'
|
9
|
+
require 'forester/tree_node_ext/validators'
|
10
|
+
require 'forester/tree_node_ext/serializers'
|
15
11
|
|
16
12
|
require 'forester/tree_node'
|
17
13
|
require 'forester/tree_factory'
|
14
|
+
|
15
|
+
module Forester
|
16
|
+
def self.tree_factory
|
17
|
+
@tree_factory ||= TreeFactory.new
|
18
|
+
end
|
19
|
+
end
|
@@ -1,76 +1,45 @@
|
|
1
1
|
module Forester
|
2
|
-
|
3
|
-
|
4
|
-
extend self
|
5
|
-
|
6
|
-
def node_from_hash(hash, options = {}, &block)
|
7
|
-
# TODO remove the whole node_content folder in next major version
|
8
|
-
# and let the user choose a class for the contents via a custom parser.
|
9
|
-
# That class should have the interface of the one used by the default parser.
|
10
|
-
# The default parser should be the constructor of Hash::Accessible, which
|
11
|
-
# is defined in the gem 'hash_ext'. Add it as a runtime dependency.
|
12
|
-
do_node_from_hash(hash, nil, options, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def from_yaml_file(file, options = {})
|
16
|
-
from_hash_with_root_key(YAML.load_file(file), options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def from_root_hash(hash, options = {})
|
20
|
-
from_hash_with_root_key({ root: hash }, options)
|
21
|
-
end
|
22
|
-
|
23
|
-
def from_hash_with_root_key(hash, options = {})
|
2
|
+
class TreeFactory
|
3
|
+
def from_root_hash(root_hash, options = {})
|
24
4
|
default_options = {
|
25
|
-
|
26
|
-
children_key: :children,
|
27
|
-
root_key: :root
|
5
|
+
max_depth: :none,
|
28
6
|
}
|
29
7
|
options = default_options.merge(options)
|
30
8
|
|
31
|
-
options[:
|
9
|
+
options[:max_depth] = -2 if options[:max_depth] == :none
|
32
10
|
|
33
11
|
dummy_root = TreeNode.new('<TEMP>')
|
34
|
-
real_root = fetch_indifferently(hash, options[:root_key])
|
35
12
|
|
36
|
-
tree = with_children(dummy_root, [
|
13
|
+
tree = with_children(dummy_root, [root_hash], options.fetch(:children_key), options[:max_depth] + 1).first_child
|
37
14
|
tree.detached_subtree_copy
|
38
15
|
end
|
39
16
|
|
40
|
-
|
41
|
-
|
42
|
-
def fetch_indifferently(hash, key, default = nil)
|
43
|
-
[key, key.to_s, key.to_s.to_sym].uniq.map { |k| hash[k] }.compact.first || default || hash.fetch(root_key)
|
17
|
+
def node_from_content(content)
|
18
|
+
TreeNode.new(SecureRandom.uuid, content)
|
44
19
|
end
|
45
20
|
|
21
|
+
private
|
22
|
+
|
46
23
|
def with_children(tree_node, children, children_key, levels_remaining)
|
47
24
|
return tree_node if levels_remaining == 0
|
25
|
+
|
48
26
|
children.each do |child_hash|
|
49
|
-
child_node =
|
50
|
-
child_children =
|
27
|
+
child_node = node_from_hash(child_hash, children_key)
|
28
|
+
child_children = child_hash.fetch(children_key, [])
|
51
29
|
|
52
30
|
tree_node << with_children(child_node, child_children, children_key, levels_remaining - 1)
|
53
31
|
end
|
32
|
+
|
54
33
|
tree_node
|
55
34
|
end
|
56
35
|
|
57
|
-
def
|
58
|
-
content =
|
59
|
-
|
36
|
+
def node_from_hash(hash, children_key)
|
37
|
+
content = without_key(hash, children_key)
|
38
|
+
node_from_content(content)
|
60
39
|
end
|
61
40
|
|
62
|
-
def
|
63
|
-
|
64
|
-
uid: SecureRandom.uuid
|
65
|
-
}
|
66
|
-
options = default_options.merge(options)
|
67
|
-
|
68
|
-
name = options[:uid]
|
69
|
-
new_node = TreeNode.new(name, content)
|
70
|
-
|
71
|
-
yield new_node if block_given?
|
72
|
-
new_node
|
41
|
+
def without_key(hash, key)
|
42
|
+
hash.dup.tap { |h| h.delete(key) }
|
73
43
|
end
|
74
|
-
|
75
44
|
end
|
76
45
|
end
|