compath 0.1.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 +7 -0
- data/.compath.yml +40 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/compath.gemspec +28 -0
- data/exe/compath +6 -0
- data/lib/compath.rb +10 -0
- data/lib/compath/cli.rb +18 -0
- data/lib/compath/config_loader.rb +17 -0
- data/lib/compath/dumper.rb +23 -0
- data/lib/compath/finder.rb +18 -0
- data/lib/compath/guide.rb +56 -0
- data/lib/compath/guide_book.rb +38 -0
- data/lib/compath/path_sorter.rb +23 -0
- data/lib/compath/version.rb +3 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13ff6ad5e1899247bca89f8bd27add568875a13f
|
4
|
+
data.tar.gz: 5ef47ad90cce237d8202eeb9ab200411a57b2b15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54aad8dc41dc0a507e69690f0b2173579b0ab7e5876af68fcfaabced03ead3a8ad57f15062238a94fd25c62a08cf031c48f8b0124e346a0abc2fa1c4ec01f93a
|
7
|
+
data.tar.gz: e563de75032cde00c6dba69d43ab0d2b23f9feedaf271e67ed0e6a522709d9abb25e88743e23c28629667497356f5c8bb32cfa84556d109d4909a2d7bfbf9945
|
data/.compath.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
- ".gitignore":
|
3
|
+
desc:
|
4
|
+
- ".rspec":
|
5
|
+
desc: Configuration file for RSpec
|
6
|
+
- ".travis.yml":
|
7
|
+
desc: Configuration file for travis
|
8
|
+
- bin/:
|
9
|
+
desc:
|
10
|
+
- bin/console:
|
11
|
+
desc:
|
12
|
+
- bin/setup:
|
13
|
+
desc:
|
14
|
+
- compath.gemspec:
|
15
|
+
desc:
|
16
|
+
- exe/:
|
17
|
+
desc:
|
18
|
+
- exe/compath:
|
19
|
+
desc:
|
20
|
+
- Gemfile:
|
21
|
+
desc:
|
22
|
+
- lib/:
|
23
|
+
desc:
|
24
|
+
- lib/compath/:
|
25
|
+
desc:
|
26
|
+
scan: false
|
27
|
+
- lib/compath.rb:
|
28
|
+
desc:
|
29
|
+
- LICENSE.txt:
|
30
|
+
desc:
|
31
|
+
- Rakefile:
|
32
|
+
desc:
|
33
|
+
- README.md:
|
34
|
+
desc:
|
35
|
+
- spec/:
|
36
|
+
desc:
|
37
|
+
- spec/compath_spec.rb:
|
38
|
+
desc:
|
39
|
+
- spec/spec_helper.rb:
|
40
|
+
desc:
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 meganemura
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
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
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Compath
|
2
|
+
|
3
|
+
Compath generates a guide of directory structure in the project.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install compath
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ compath --file=.compath.yml
|
12
|
+
|
13
|
+
It creates or updates `.compath.yml`.
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
- ".gitignore":
|
17
|
+
desc:
|
18
|
+
- bin/:
|
19
|
+
desc:
|
20
|
+
- bin/console:
|
21
|
+
desc:
|
22
|
+
- bin/setup:
|
23
|
+
desc:
|
24
|
+
|
25
|
+
...
|
26
|
+
```
|
27
|
+
|
28
|
+
Each object of sequences has a key to object structure.
|
29
|
+
The key means path, and the object is only able to have `desc` or `scan/` keys.
|
30
|
+
`desc` is to describe what the path means.
|
31
|
+
`scan` is to switch scanning files or not for the directory by configuring boolean value (`true`, `false`).
|
32
|
+
|
33
|
+
With the following config, `compath` does not scan files of `bin/` directory.
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
- ".gitignore":
|
37
|
+
desc:
|
38
|
+
- bin/:
|
39
|
+
desc:
|
40
|
+
scan: false
|
41
|
+
|
42
|
+
...
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/meganemura/compath.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/compath.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "compath/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "compath"
|
8
|
+
spec.version = Compath::VERSION
|
9
|
+
spec.authors = ["meganemura"]
|
10
|
+
spec.email = ["meganemura@users.noreply.github.com"]
|
11
|
+
|
12
|
+
spec.summary = "Compath generates a guide of directory structure in the project"
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/meganemura/compath"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
end
|
data/exe/compath
ADDED
data/lib/compath.rb
ADDED
data/lib/compath/cli.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Compath
|
2
|
+
class CLI
|
3
|
+
def self.run
|
4
|
+
finder = Compath::Finder.new
|
5
|
+
paths = Compath::PathSorter.sort(finder.paths.keys)
|
6
|
+
|
7
|
+
config = Compath::ConfigLoader.load(File.read('.compath.yml'))
|
8
|
+
|
9
|
+
guides = paths.map {|path| Compath::Guide.new(path) }
|
10
|
+
guide_book = Compath::GuideBook.new(guides)
|
11
|
+
guide_book.merge(config)
|
12
|
+
|
13
|
+
yaml = guide_book.publish_yaml
|
14
|
+
|
15
|
+
puts yaml
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Compath
|
2
|
+
module ConfigLoader
|
3
|
+
module_function
|
4
|
+
def load(config)
|
5
|
+
conf = YAML.load(config)
|
6
|
+
|
7
|
+
guides = conf.map do |guide_hash|
|
8
|
+
path = guide_hash.keys.first
|
9
|
+
options = guide_hash.values.first
|
10
|
+
options = options.each_with_object({}) do |(key, value), hash|
|
11
|
+
hash[key.to_sym] = value
|
12
|
+
end
|
13
|
+
Guide.new(path, **options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Compath
|
2
|
+
class Dumper
|
3
|
+
def initialize(paths)
|
4
|
+
@paths = paths.each_with_object({}) do |path, hash|
|
5
|
+
hash[path] = Guide.new(path)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def dump
|
10
|
+
@paths.values.map do |path|
|
11
|
+
scan_target = true
|
12
|
+
scan_target = path.ancestors.all?(&:scan_children)
|
13
|
+
next unless scan_target
|
14
|
+
path.to_object
|
15
|
+
end.compact
|
16
|
+
end
|
17
|
+
alias_method :dump_hash, :dump
|
18
|
+
|
19
|
+
def dump_yaml
|
20
|
+
YAML.dump(dump_hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Compath
|
2
|
+
class Finder
|
3
|
+
def files
|
4
|
+
@files ||= begin
|
5
|
+
files = `git ls-files -z`.split("\x0")
|
6
|
+
files.map {|file| Pathname.new(file) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def paths
|
11
|
+
files.each_with_object({}) do |file, hash|
|
12
|
+
file.descend do |pathname|
|
13
|
+
hash[pathname.to_path] = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Compath
|
2
|
+
class Guide
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegators :@pathname, :directory?, :executable?, :to_path
|
6
|
+
attr_reader :pathname, :scan_children
|
7
|
+
|
8
|
+
def initialize(path, scan: true, desc: nil)
|
9
|
+
# claenpath is for dirty configurated guide
|
10
|
+
@pathname = Pathname.new(path).cleanpath
|
11
|
+
@scan_children = scan
|
12
|
+
@description = desc
|
13
|
+
end
|
14
|
+
|
15
|
+
def children
|
16
|
+
pathname.children.map do |child|
|
17
|
+
self.class.new(child.to_path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ancestors
|
22
|
+
ancestors = []
|
23
|
+
pathname.ascend do |path|
|
24
|
+
next if path == pathname
|
25
|
+
ancestors << self.class.new(path.to_path)
|
26
|
+
end
|
27
|
+
ancestors
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_object
|
31
|
+
scan_or_not = if !directory? || @scan_children
|
32
|
+
{}
|
33
|
+
else
|
34
|
+
{
|
35
|
+
'scan' => false
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
object = {
|
40
|
+
object_key => {
|
41
|
+
'desc' => @description
|
42
|
+
}.merge(scan_or_not)
|
43
|
+
}
|
44
|
+
|
45
|
+
object
|
46
|
+
end
|
47
|
+
|
48
|
+
def object_key
|
49
|
+
if directory?
|
50
|
+
pathname.to_s + '/'
|
51
|
+
else
|
52
|
+
pathname.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Compath
|
2
|
+
class GuideBook
|
3
|
+
attr_reader :paths
|
4
|
+
def initialize(guides)
|
5
|
+
@index = guides.each_with_object({}) do |guide, hash|
|
6
|
+
hash[guide.to_path] = guide
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def guides
|
11
|
+
@index.values
|
12
|
+
end
|
13
|
+
|
14
|
+
def merge(new_guides)
|
15
|
+
new_guides.each do |guide|
|
16
|
+
puts guide.to_path
|
17
|
+
if @index.key?(guide.to_path)
|
18
|
+
@index[guide.to_path] = guide
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def publish
|
24
|
+
guides.map do |guide|
|
25
|
+
scan_children = true
|
26
|
+
scan_children = guide.ancestors.all? do |ancestor|
|
27
|
+
@index[ancestor.to_path].scan_children
|
28
|
+
end
|
29
|
+
next unless scan_children
|
30
|
+
guide.to_object
|
31
|
+
end.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
def publish_yaml
|
35
|
+
YAML.dump(publish)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Compath
|
2
|
+
# TODO: Remove Pathname
|
3
|
+
module PathSorter
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def sort(paths)
|
7
|
+
sorted_pathnames.map(&:to_path) & paths
|
8
|
+
end
|
9
|
+
|
10
|
+
def sorted_pathnames(path = '.')
|
11
|
+
collected = []
|
12
|
+
current = Pathname.new(path)
|
13
|
+
if current.directory?
|
14
|
+
collected << current
|
15
|
+
collected += current.children.flat_map { |child| sorted_pathnames(child) }
|
16
|
+
else
|
17
|
+
collected << current
|
18
|
+
end
|
19
|
+
|
20
|
+
collected
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compath
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- meganemura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-10 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Compath generates a guide of directory structure in the project
|
70
|
+
email:
|
71
|
+
- meganemura@users.noreply.github.com
|
72
|
+
executables:
|
73
|
+
- compath
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".compath.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- compath.gemspec
|
88
|
+
- exe/compath
|
89
|
+
- lib/compath.rb
|
90
|
+
- lib/compath/cli.rb
|
91
|
+
- lib/compath/config_loader.rb
|
92
|
+
- lib/compath/dumper.rb
|
93
|
+
- lib/compath/finder.rb
|
94
|
+
- lib/compath/guide.rb
|
95
|
+
- lib/compath/guide_book.rb
|
96
|
+
- lib/compath/path_sorter.rb
|
97
|
+
- lib/compath/version.rb
|
98
|
+
homepage: https://github.com/meganemura/compath
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.5.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Compath generates a guide of directory structure in the project
|
122
|
+
test_files: []
|