dir_tree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84873dccd596c686c89def1fc2d86e0b56eb3b85
4
+ data.tar.gz: 45225e5e0f017ff172f8b1ae24d019d0bd439e7f
5
+ SHA512:
6
+ metadata.gz: 897ea9284e0e4d3adb99175ab6d0138721c220003254eef1c0be915da143e19f4f82e9cea731136f1213920a87455ca39c289b6d9d893b50959660b5f2ad3a4c
7
+ data.tar.gz: 154ca74d79b575d204462067dc06272984427e00a7599e3d09c6af2bc3b570469c62bd854456586a5b9341cef5fab56187b857a5c90dfdd954c8a127520fda86
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dir_tree.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 WAKASUGI MUBAE
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # DirTree
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dir_tree'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dir_tree
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/dir_tree/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
data/dir_tree.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dir_tree/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dir_tree"
8
+ spec.version = DirTree::VERSION
9
+ spec.authors = ["WAKASUGI 5T111111"]
10
+ spec.email = ["baenej@gmail.com"]
11
+ spec.summary = "Convert directory tree structure into a hash"
12
+ spec.description = "No description"
13
+ spec.homepage = "https://github.com/5t111111/dir_tree"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'minitest', '~> 5.5', '>= 5.5.0'
24
+ end
@@ -0,0 +1,3 @@
1
+ module DirTree
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dir_tree.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "dir_tree/version"
2
+
3
+ #
4
+ # Convert directory tree structure into a hash
5
+ #
6
+ # == Parameters:
7
+ # path::
8
+ # Root directory path for a hash
9
+ # name::
10
+ # Do not specify explicitly as it is used for recursion
11
+ #
12
+ # == Returns:
13
+ # A hash representing the directory tree structure
14
+ #
15
+ module DirTree
16
+ def self.hash_tree(path, name = nil)
17
+ key = name || path
18
+ data = {}
19
+ data[key] = children = {}
20
+ Dir.foreach(path) do |entry|
21
+ next if entry == '..' || entry == '.'
22
+ full_path = File.join(path, entry)
23
+ if File.directory?(full_path)
24
+ children.update(hash_tree(full_path, entry))
25
+ else
26
+ children[entry] = {}
27
+ end
28
+ end
29
+ data
30
+ end
31
+ end
32
+
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'dir_tree'
3
+
4
+ require 'minitest/autorun'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestDirTree < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @test_path = File.expand_path(File.dirname(__FILE__))
7
+ end
8
+
9
+ def test_that_it_has_a_version_number
10
+ refute_nil ::DirTree::VERSION
11
+ end
12
+
13
+ def test_it_returns_hash_representing_diretcory_tree
14
+ # ├── root
15
+ # │   ├── dir_1
16
+ # │   │   ├── file_in_dir_1_1
17
+ # │   │   └── file_in_dir_1_2
18
+ # │   ├── dir_2
19
+ # │   │   ├── dir_3
20
+ # │   │   │   ├── file_in_dir_3_1
21
+ # │   │   │   └── file_in_dir_3_2
22
+ # │   │   ├── file_in_dir_2_1
23
+ # │   │   └── file_in_dir_2_2
24
+ # │   ├── file_in_root_1
25
+ # │   └── file_in_root_2
26
+ expected = { File.join(@test_path, 'root') =>
27
+ { "dir_1" =>
28
+ { "file_in_dir_1_1" => {},
29
+ "file_in_dir_1_2" => {}},
30
+ "dir_2" =>
31
+ { "dir_3" =>
32
+ { "file_in_dir_3_1" => {},
33
+ "file_in_dir_3_2" => {}},
34
+ "file_in_dir_2_1" => {},
35
+ "file_in_dir_2_2" => {}},
36
+ "file_in_root_1" => {},
37
+ "file_in_root_2" => {}}}
38
+ actual = DirTree.hash_tree(File.join(@test_path, 'root'))
39
+ assert_equal expected, actual
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dir_tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - WAKASUGI 5T111111
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.5'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 5.5.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '5.5'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 5.5.0
61
+ description: No description
62
+ email:
63
+ - baenej@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - dir_tree.gemspec
75
+ - lib/dir_tree.rb
76
+ - lib/dir_tree/version.rb
77
+ - test/minitest_helper.rb
78
+ - test/root/dir_1/file_in_dir_1_1
79
+ - test/root/dir_1/file_in_dir_1_2
80
+ - test/root/dir_2/dir_3/file_in_dir_3_1
81
+ - test/root/dir_2/dir_3/file_in_dir_3_2
82
+ - test/root/dir_2/file_in_dir_2_1
83
+ - test/root/dir_2/file_in_dir_2_2
84
+ - test/root/file_in_root_1
85
+ - test/root/file_in_root_2
86
+ - test/test_dir_tree.rb
87
+ homepage: https://github.com/5t111111/dir_tree
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Convert directory tree structure into a hash
111
+ test_files:
112
+ - test/minitest_helper.rb
113
+ - test/root/dir_1/file_in_dir_1_1
114
+ - test/root/dir_1/file_in_dir_1_2
115
+ - test/root/dir_2/dir_3/file_in_dir_3_1
116
+ - test/root/dir_2/dir_3/file_in_dir_3_2
117
+ - test/root/dir_2/file_in_dir_2_1
118
+ - test/root/dir_2/file_in_dir_2_2
119
+ - test/root/file_in_root_1
120
+ - test/root/file_in_root_2
121
+ - test/test_dir_tree.rb