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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -8
  3. data/lib/key_tree.rb +15 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd5943f0ff79e95fe0502727ee34210bf3c38cd4b0be9b22ff95bd4dc33c62cb
4
- data.tar.gz: d6b7c80b073dc158774f34df101dc42d5341a727a64bc8d89c8b2bc7ac275a86
3
+ metadata.gz: 88a507ce5dd70323ccb58dacefa9bb7bcbdb9479b977f086c09cfe3409326341
4
+ data.tar.gz: 205f90e3467562c846a0139cba358879f4942fc8fa6f91e726af5325f9093baf
5
5
  SHA512:
6
- metadata.gz: dbc0abd4371d7a0eb568fbd3475cfa73da11cf906e9ef79c19afd7d3563661d88e7b6aa7c73a2377202e4c6babda62a8b6f14bec9e271c4f3aad3901ca668f13
7
- data.tar.gz: a52df06a65e2ea6a1dba39bb71f6cdcb8cdf0bb54a396442c4cf51208cc97831538f6a689d3ecb67565e60d1a88dabe68c2dc071f578e807e601b6807850772c
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/key_tree`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/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.
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/[USERNAME]/key_tree/blob/master/CODE_OF_CONDUCT.md).
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+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calle Englund