key_tree 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -8
- data/lib/key_tree.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88a507ce5dd70323ccb58dacefa9bb7bcbdb9479b977f086c09cfe3409326341
|
4
|
+
data.tar.gz: 205f90e3467562c846a0139cba358879f4942fc8fa6f91e726af5325f9093baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9df024317615e4ac92d1b552fc1c8adc51acb3dc9f1af9e1636cbdd2edb1e6db986cbcfb6ff1b00ff974ad91c4c0383be5e1ff1d909a0027745047521d315da
|
7
|
+
data.tar.gz: d34833616cc2eecb57630715e3a98c3a850c28257b670a22c9b99c5a5481f69c237244198a8e0967b434cdd58adb6da0096aa7449e242d1d069cbb68ec039c0f
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/key_tree.svg)](https://badge.fury.io/rb/key_tree)
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/key_tree.svg)](https://badge.fury.io/rb/key_tree) [![Maintainability](https://api.codeclimate.com/v1/badges/ac48756e80007e0cd6f9/maintainability)](https://codeclimate.com/github/notCalle/ruby-keytree/maintainability)
|
2
2
|
|
3
3
|
# KeyTree
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
5
|
+
KeyTree manages trees of hashes, and (possibly nested) forests of such trees,
|
6
|
+
allowing access to values by key path.
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
@@ -24,17 +23,26 @@ Or install it yourself as:
|
|
24
23
|
|
25
24
|
## Usage
|
26
25
|
|
27
|
-
|
26
|
+
```ruby
|
27
|
+
kt=KeyTree::Tree[a: { b: 1 }]
|
28
|
+
kt['a.b']
|
29
|
+
=> 1
|
30
|
+
kf=KeyTree::Forest[kt, {b: { c: 2 }}]
|
31
|
+
kt['a.b']
|
32
|
+
=> 1
|
33
|
+
kf['b.c']
|
34
|
+
=> 2
|
35
|
+
```
|
28
36
|
|
29
37
|
## Development
|
30
38
|
|
31
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
40
|
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
34
42
|
|
35
43
|
## Contributing
|
36
44
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/notCalle/key_tree. 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.
|
38
46
|
|
39
47
|
## License
|
40
48
|
|
@@ -42,4 +50,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
42
50
|
|
43
51
|
## Code of Conduct
|
44
52
|
|
45
|
-
Everyone interacting in the KeyTree project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
53
|
+
Everyone interacting in the KeyTree project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/notCalle/key_tree/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/key_tree.rb
CHANGED
@@ -60,6 +60,21 @@ module KeyTree
|
|
60
60
|
yield(keytree)
|
61
61
|
end
|
62
62
|
|
63
|
+
# Open all files in a directory and load their contents into
|
64
|
+
# a Forest of Trees, optionally following symlinks, and recursing.
|
65
|
+
def self.open_all(dir_name, follow_links: false, recurse: false)
|
66
|
+
Dir.children(dir_name).reduce(KeyTree::Forest.new) do |result, file|
|
67
|
+
path = File.join(dir_name, file)
|
68
|
+
next result if File.symlink?(path) && !follow_links
|
69
|
+
stat = File.stat(path)
|
70
|
+
# rubocop:disable Security/Open
|
71
|
+
next result << open(path) if stat.file?
|
72
|
+
# rubocop:enable Security/Open
|
73
|
+
next result unless recurse && stat.directory?
|
74
|
+
result << open_all(path, follow_links: follow_links, recurse: true)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
63
78
|
private_class_method
|
64
79
|
|
65
80
|
# Get a class for loading external serialization for +type+
|