dir_friend 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/dir_friend +5 -0
- data/dir_friend.gemspec +28 -0
- data/lib/dir_friend/any.rb +11 -0
- data/lib/dir_friend/command.rb +68 -0
- data/lib/dir_friend/d.rb +77 -0
- data/lib/dir_friend/f.rb +37 -0
- data/lib/dir_friend/graph.rb +87 -0
- data/lib/dir_friend/version.rb +3 -0
- data/lib/dir_friend.rb +14 -0
- data/spec/dir_friend_spec.rb +160 -0
- data/spec/graph_spec.rb +29 -0
- data/spec/spec_helper.rb +2 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab2ec3564188d8791883ab97345279fc8876a8e2
|
4
|
+
data.tar.gz: e801fc5176c0436fe712911e5854eb660bc0658a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 638106caded9997d31321616e8106f52d4aea65cdad3e907481b31213a215f59dacc7357237b55e484c1a80e33f82a257a57138f75a90c84dcd5948b6c5959cc
|
7
|
+
data.tar.gz: 021820b1119ee331e49e0aca5d0568204149c45ae508d38bf2b191c4d831d347d9ecac70e03399b251cb7c9186158611a04a8fca7ccf4c6b272caca2084e04fb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 kyoendo
|
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,86 @@
|
|
1
|
+
# DirFriend
|
2
|
+
|
3
|
+
`DirFriend` is a tool for visualizing file directory.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dir_friend'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dir_friend
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
In your terminal, try followings;
|
22
|
+
|
23
|
+
# Show help
|
24
|
+
% dir_friend
|
25
|
+
|
26
|
+
# Create a dot file for path/to/project
|
27
|
+
% dir_friend dot path/to/project
|
28
|
+
|
29
|
+
# Create with some options
|
30
|
+
% dir_friend dot path/to/project -c blues --dir_shape box
|
31
|
+
% dir_friend dot path/to/project -g "bgcolor:azure,rkdir:LR,splines:ortho"
|
32
|
+
|
33
|
+
In your ruby script;
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'dir_friend'
|
37
|
+
|
38
|
+
dir = DirFriend::D.new('path/to/project')
|
39
|
+
|
40
|
+
# Show info
|
41
|
+
dir.info #=> {:directories=>7, :files=>2, :depth=>3}
|
42
|
+
|
43
|
+
# Show children in the directory
|
44
|
+
puts dir.entries
|
45
|
+
>> F: Gemfile
|
46
|
+
>> D: lib
|
47
|
+
>> F: LICENSE.txt
|
48
|
+
>> F: myproject.gemspec
|
49
|
+
>> F: Rakefile
|
50
|
+
>> F: README.md
|
51
|
+
|
52
|
+
# Traverse all files and directories under the directory
|
53
|
+
dir.each do |f|
|
54
|
+
puts f.path
|
55
|
+
end
|
56
|
+
>> /project/myproject/Gemfile
|
57
|
+
>> /project/myproject/lib
|
58
|
+
>> /project/myproject/lib/myproject
|
59
|
+
>> /project/myproject/lib/myproject/version.rb
|
60
|
+
>> /project/myproject/lib/myproject.rb
|
61
|
+
>> /project/myproject/LICENSE.txt
|
62
|
+
>> /project/myproject/myproject.gemspec
|
63
|
+
>> /project/myproject/Rakefile
|
64
|
+
>> /project/myproject/README.md
|
65
|
+
|
66
|
+
# Output a dot data(Gviz object)
|
67
|
+
puts dir.to_dot # => dot data
|
68
|
+
|
69
|
+
# with options
|
70
|
+
opt = {colorscheme:greens, layout:'fdp', global:"bgcolor:azure,splines:ortho" }
|
71
|
+
puts dir.to_dot(opt)
|
72
|
+
|
73
|
+
# Save to a file
|
74
|
+
dir.to_dot.save(:mydot)
|
75
|
+
|
76
|
+
# Open Graphviz.app with tempfile for dot data(mac only)
|
77
|
+
dir.to_dot open:true
|
78
|
+
```
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. Fork it
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/dir_friend
ADDED
data/dir_friend.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 'dir_friend/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dir_friend"
|
8
|
+
spec.version = DirFriend::VERSION
|
9
|
+
spec.authors = ["kyoendo"]
|
10
|
+
spec.email = ["postagie@gmail.com"]
|
11
|
+
spec.description = %q{`DirFriend` is a tool for visualizing file directory.}
|
12
|
+
spec.summary = %q{`DirFriend` is a tool for visualizing file directory.}
|
13
|
+
spec.homepage = "https://github.com/melborne/dir_friend"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency 'gviz'
|
22
|
+
spec.add_dependency 'thor'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "fakefs"
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module DirFriend
|
4
|
+
class Command < Thor
|
5
|
+
|
6
|
+
desc "info PATH", "Show PATH info"
|
7
|
+
def info(path)
|
8
|
+
puts Any.new(path).info
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "dot PATH", "Create a graphviz dot file for PATH"
|
12
|
+
long_desc <<-EOS
|
13
|
+
ex.
|
14
|
+
|
15
|
+
`dir_friend dot path/ -l fdp -c blues, -e "arrowhead:none"`
|
16
|
+
|
17
|
+
`dir_friend dot path/ -g "bgcolor:lime,rkdir:LR,splines:ortho"`
|
18
|
+
EOS
|
19
|
+
option :layout, aliases:"-l"
|
20
|
+
option :colorscheme, aliases:"-c"
|
21
|
+
option :dir_shape
|
22
|
+
option :file_shape
|
23
|
+
option :global, aliases:"-g"
|
24
|
+
option :nodes, aliases:"-n"
|
25
|
+
option :edges, aliases:"-e"
|
26
|
+
option :save, aliases:"-s", default:'a'
|
27
|
+
option :depth, aliases:"-d", default:9
|
28
|
+
def dot(path)
|
29
|
+
opt = options.dup.inject({}) { |h, (k,v)| h[k.intern] = v; h }
|
30
|
+
save_path = opt.delete(:save)
|
31
|
+
opt = opt_parser(opt)
|
32
|
+
dir = D.new(path, depth:options[:depth].to_i)
|
33
|
+
dir.to_dot(opt).save(save_path)
|
34
|
+
puts "Dot file created: `#{save_path}.dot`"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "version", "Show DirFriend version"
|
38
|
+
def version
|
39
|
+
puts "DirFriend #{DirFriend::VERSION} (c) 2013 kyoendo"
|
40
|
+
end
|
41
|
+
map "-v" => :version
|
42
|
+
|
43
|
+
desc "banner", "Describe DirFriend usage", hide:true
|
44
|
+
def banner
|
45
|
+
banner = <<-EOS
|
46
|
+
DirFriend is a tool for visualizing file directory.
|
47
|
+
EOS
|
48
|
+
puts banner
|
49
|
+
help
|
50
|
+
end
|
51
|
+
default_task :banner
|
52
|
+
map "-h" => :banner
|
53
|
+
|
54
|
+
no_commands do
|
55
|
+
def opt_parser(opt)
|
56
|
+
%i(global nodes edges).each do |attr|
|
57
|
+
if kv = opt.delete(attr)
|
58
|
+
kv_arr = kv.split(/\s*,\s*/)
|
59
|
+
.map{ |kv| kv.split(/\s*:\s*/).map(&:strip) }
|
60
|
+
.map{ |k, v| [k.intern, v] }
|
61
|
+
opt.update({attr => Hash[ kv_arr ]})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
opt
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/dir_friend/d.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module DirFriend
|
4
|
+
class OS
|
5
|
+
def self.mac?
|
6
|
+
RbConfig::CONFIG['host_os'].match /mac|darwin/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class D < F
|
11
|
+
include Enumerable
|
12
|
+
attr_reader :entries
|
13
|
+
def initialize(name='.', level:0, depth:Float::MAX.to_i)
|
14
|
+
super(name, level:level)
|
15
|
+
@entries = []
|
16
|
+
build(depth) if depth >= 1
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def each(&blk)
|
21
|
+
entries.each do |e|
|
22
|
+
blk.call(e)
|
23
|
+
e.each(&blk) if e.is_a?(D)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def info
|
28
|
+
dirs, files = group_by { |f| f.is_a? D }.map { |_, fs| fs.size }
|
29
|
+
{directories: dirs, files: files, depth: depth}
|
30
|
+
end
|
31
|
+
|
32
|
+
def up
|
33
|
+
D.new path.sub(/\/[^\/]+$/, '')
|
34
|
+
end
|
35
|
+
|
36
|
+
def down(child=nil)
|
37
|
+
unless child
|
38
|
+
min = entries.select(&:directory?).min
|
39
|
+
return min unless min
|
40
|
+
child = min.name
|
41
|
+
end
|
42
|
+
D.new File.join(path, child)
|
43
|
+
end
|
44
|
+
|
45
|
+
def depth
|
46
|
+
@depth ||= map(&:level).max
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"D: #{name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_dot(opt={})
|
54
|
+
graph = DirFriend::Graph.new(self)
|
55
|
+
if opt.delete(:open) && OS.mac?
|
56
|
+
Tempfile.open(['dirfriend', '.dot']) do |f|
|
57
|
+
f.puts graph.build(opt)
|
58
|
+
if system("open", f.path)
|
59
|
+
puts "Graphviz opened tempfile: #{f.path}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
graph.build(opt)
|
64
|
+
end
|
65
|
+
rescue
|
66
|
+
abort "something go wrong."
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def build(depth)
|
71
|
+
entries = Dir[File.join(path, '*')]
|
72
|
+
entries.each do |ent|
|
73
|
+
@entries << Any.new(ent, level:level+1, depth:depth-1)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/dir_friend/f.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module DirFriend
|
2
|
+
class F
|
3
|
+
include Comparable
|
4
|
+
attr_reader :name, :path, :level, :stat
|
5
|
+
def initialize(name, level:0)
|
6
|
+
@path = File.expand_path(name)
|
7
|
+
@name = File.basename(@path)
|
8
|
+
@stat = File.stat(@path)
|
9
|
+
@level = level
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *a, &b)
|
13
|
+
stat_methods = stat.class.instance_methods(false)
|
14
|
+
return super unless stat_methods.include?(name)
|
15
|
+
stat.__send__(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
self.path == other.path
|
20
|
+
end
|
21
|
+
alias :eql? :==
|
22
|
+
|
23
|
+
def <=>(other)
|
24
|
+
self.name <=> other.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def info
|
28
|
+
format = %i(mode nlink uid gid size mtime)
|
29
|
+
arr = format.map { |attr| [attr, stat.send(attr)] }
|
30
|
+
Hash[ arr ]
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
"F: #{name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module DirFriend
|
2
|
+
class Graph
|
3
|
+
def initialize(dir)
|
4
|
+
@dir = dir
|
5
|
+
end
|
6
|
+
|
7
|
+
def render(opt={})
|
8
|
+
build(opt).to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
# Build a graphviz dot data using Gviz
|
12
|
+
# opt keys: :layout, :colorscheme, :dir_shape, :file_shape,
|
13
|
+
# :graph(or global), :nodes, :edges
|
14
|
+
# ex. layout:'fdp', colorscheme:'blues', graph:{splines:'ortho'}
|
15
|
+
def build(opt)
|
16
|
+
global_opt, nodes_opt, edges_opt, dir_shape, file_shape = opt_parser(opt)
|
17
|
+
|
18
|
+
dirs = [@dir] + @dir.select(&:directory?)
|
19
|
+
|
20
|
+
gv = ::Gviz.new
|
21
|
+
gv.global global_opt
|
22
|
+
gv.nodes nodes_opt
|
23
|
+
gv.edges edges_opt
|
24
|
+
dirs.each do |d|
|
25
|
+
# files
|
26
|
+
d.entries.each do |ent|
|
27
|
+
c, fc = color_id(ent.level, nodes_opt[:style])
|
28
|
+
gv.node ent.path.to_id, label:ent.name, shape:file_shape,
|
29
|
+
color:c, fontcolor:fc
|
30
|
+
end
|
31
|
+
|
32
|
+
# directory
|
33
|
+
c, fc = color_id(d.level, nodes_opt[:style])
|
34
|
+
gv.node d.path.to_id, label:d.name, shape:dir_shape,
|
35
|
+
color:c, fontcolor:fc
|
36
|
+
|
37
|
+
# route dir => children
|
38
|
+
gv.route d.path.to_id => d.entries.map{ |ch| ch.path.to_id }
|
39
|
+
end
|
40
|
+
gv
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def opt_parser(opt)
|
45
|
+
global = opt[:global] || opt[:graph] || {layout:'dot'}
|
46
|
+
global = global.merge(layout:opt[:layout]) if opt[:layout]
|
47
|
+
|
48
|
+
nodes = opt[:nodes] || {}
|
49
|
+
if cs = (nodes[:colorscheme] || opt[:colorscheme])
|
50
|
+
cs = opt_color_parser(cs)
|
51
|
+
nodes.update(style:'filled', colorscheme:cs)
|
52
|
+
end
|
53
|
+
|
54
|
+
edges = opt[:edges] || {}
|
55
|
+
dir_shape = opt[:dir_shape] || nodes[:shape] || 'ellipse'
|
56
|
+
file_shape = opt[:file_shape] || nodes[:shape] || 'ellipse'
|
57
|
+
|
58
|
+
[global, nodes, edges, dir_shape, file_shape]
|
59
|
+
end
|
60
|
+
|
61
|
+
def opt_color_parser(color)
|
62
|
+
unless color.match(/\w\d$/) #end with one digit number
|
63
|
+
color = "#{color}#{color_depth}"
|
64
|
+
end
|
65
|
+
color
|
66
|
+
end
|
67
|
+
|
68
|
+
def color_depth
|
69
|
+
depth = @dir.depth + 1
|
70
|
+
if depth > 9 then 9
|
71
|
+
elsif depth < 3 then 3
|
72
|
+
else depth
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def color_id(lv, node_style)
|
77
|
+
color = @dir.depth + 1 - lv
|
78
|
+
fontc =
|
79
|
+
if node_style && node_style.match(/filled/)
|
80
|
+
lv < ((@dir.depth+1)/2) ? 'white' : 'black'
|
81
|
+
else
|
82
|
+
'black'
|
83
|
+
end
|
84
|
+
[color, fontc]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/dir_friend.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakefs/spec_helpers'
|
3
|
+
|
4
|
+
describe DirFriend do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
it 'should have a version number' do
|
7
|
+
DirFriend::VERSION.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe DirFriend::F do
|
11
|
+
before(:each) do
|
12
|
+
File.write('foo.txt', '')
|
13
|
+
@f = DirFriend::F.new('foo.txt')
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#path' do
|
17
|
+
it 'returns a file path' do
|
18
|
+
path = File.expand_path('foo.txt')
|
19
|
+
expect(@f.path).to eq path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#stat' do
|
24
|
+
it 'returns File::Stat object' do
|
25
|
+
expect(@f.stat).to be_instance_of(File::Stat)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#method_missing' do
|
30
|
+
it 'returns instance methods of File::Stat' do
|
31
|
+
f = File::Stat.new('foo.txt')
|
32
|
+
expect(@f.size).to eq f.size
|
33
|
+
expect(@f.directory?).to eq f.directory?
|
34
|
+
expect(@f.atime).to eq f.atime
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#<=>' do
|
39
|
+
it 'returns a minimum file' do
|
40
|
+
fs = %w(c.txt b.txt a.txt).map do |f|
|
41
|
+
File.write(f, '')
|
42
|
+
DirFriend::F.new f
|
43
|
+
end
|
44
|
+
expect(fs.min).to eq fs.last
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe DirFriend::D do
|
50
|
+
before(:each) do
|
51
|
+
%w(A A/D A/D/G).each { |d| Dir.mkdir d }
|
52
|
+
%w(A/a A/b A/c A/D/e A/D/f A/D/G/h A/D/G/i).each { |f| File.write(f, '') }
|
53
|
+
@d = DirFriend::D.new('A')
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '.new' do
|
57
|
+
it 'returns current directory without argument' do
|
58
|
+
d = DirFriend::D.new
|
59
|
+
expect(d.name).to eq 'dir_friend'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#entries' do
|
64
|
+
it 'returns entries in directory' do
|
65
|
+
expect(@d.entries.map(&:name).sort).to eq %w(D a b c)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#each' do
|
70
|
+
it 'iterates whole files in directory' do
|
71
|
+
ent = @d.map(&:name).sort
|
72
|
+
expect(ent).to eq %w(D G a b c e f h i)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#info' do
|
77
|
+
it 'returns numbers of files and directories in the directory' do
|
78
|
+
info = {directories: 2, files: 7, depth: 3}
|
79
|
+
expect(@d.info).to eq info
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns a sub directory info' do
|
83
|
+
info = {directories: 1, files: 4, depth: 2}
|
84
|
+
expect(@d.down('D').info).to eq info
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#up' do
|
89
|
+
it 'returns a parent directory object' do
|
90
|
+
d = DirFriend::D.new('A/D')
|
91
|
+
up = d.up
|
92
|
+
expect(up).to eq @d
|
93
|
+
expect(up.level).to eq 0
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#down' do
|
98
|
+
it 'returns a child directory object' do
|
99
|
+
d = DirFriend::D.new('A/D')
|
100
|
+
down = @d.down('D')
|
101
|
+
expect(down).to eq d
|
102
|
+
expect(down.level).to eq 0
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns a child child directory object' do
|
106
|
+
d = DirFriend::D.new('A/D/G')
|
107
|
+
down = @d.down('D/G')
|
108
|
+
expect(down).to eq d
|
109
|
+
expect(down.level).to eq 0
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns a minimum child when no argument supplied' do
|
113
|
+
Dir.mkdir('A/C')
|
114
|
+
d1 = DirFriend::D.new('A')
|
115
|
+
d2 = DirFriend::D.new('A/C')
|
116
|
+
down = d1.down
|
117
|
+
expect(down).to eq d2
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#to_dot' do
|
122
|
+
before(:each) do
|
123
|
+
@d = DirFriend::D.new('A/D/G')
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns a dot graph file' do
|
127
|
+
words = %w(layout="dot")
|
128
|
+
test = words.all? { |w| @d.to_dot(open:false).to_s.include? w }
|
129
|
+
expect(test).to be_true
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'accept some graph arguments with keywords' do
|
134
|
+
opt = {layout:'fdp', colorscheme:'rdpu4', open:false}
|
135
|
+
words = %w(layout="fdp" colorscheme="rdpu4")
|
136
|
+
test = words.all? { |w| @d.to_dot(opt).to_s.include? w }
|
137
|
+
expect(test).to be_true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe DirFriend::Any do
|
143
|
+
before(:each) do
|
144
|
+
%w(A A/D A/D/G).each { |d| Dir.mkdir d }
|
145
|
+
%w(A/a A/b A/c A/D/e A/D/f A/D/G/h A/D/G/i).each { |f| File.write(f, '') }
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '.new' do
|
149
|
+
it 'returns a F object when the arg is a file' do
|
150
|
+
any = DirFriend::Any.new('A/a')
|
151
|
+
expect(any).to be_instance_of(DirFriend::F)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns a D object when the arg is a directory' do
|
155
|
+
any = DirFriend::Any.new('A')
|
156
|
+
expect(any).to be_instance_of(DirFriend::D)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/graph_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakefs/spec_helpers'
|
3
|
+
|
4
|
+
describe DirFriend::Graph do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
%w(A A/D A/D/G).each { |d| Dir.mkdir d }
|
9
|
+
%w(A/a A/b A/c A/D/e A/D/f A/D/G/h A/D/G/i).each { |f| File.write(f, '') }
|
10
|
+
@d = DirFriend::D.new('A')
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#render' do
|
14
|
+
it 'reutrns dot data w/o opt' do
|
15
|
+
g = DirFriend::Graph.new(@d).render
|
16
|
+
words = %w(digraph)
|
17
|
+
test = words.all? { |w| g.include? w }
|
18
|
+
expect(test).to be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'reutrns dot data with layout, colorscheme, and node shape data' do
|
22
|
+
opt = {layout:'fdp', colorscheme:'greens', nodes:{shape:'box'}}
|
23
|
+
g = DirFriend::Graph.new(@d).render(opt)
|
24
|
+
words = %w(colorscheme="greens4" layout="fdp" shape="box")
|
25
|
+
test = words.all? { |w| g.include? w }
|
26
|
+
expect(test).to be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dir_friend
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kyoendo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gviz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakefs
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: '`DirFriend` is a tool for visualizing file directory.'
|
98
|
+
email:
|
99
|
+
- postagie@gmail.com
|
100
|
+
executables:
|
101
|
+
- dir_friend
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .rspec
|
107
|
+
- .travis.yml
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/dir_friend
|
113
|
+
- dir_friend.gemspec
|
114
|
+
- lib/dir_friend.rb
|
115
|
+
- lib/dir_friend/any.rb
|
116
|
+
- lib/dir_friend/command.rb
|
117
|
+
- lib/dir_friend/d.rb
|
118
|
+
- lib/dir_friend/f.rb
|
119
|
+
- lib/dir_friend/graph.rb
|
120
|
+
- lib/dir_friend/version.rb
|
121
|
+
- spec/dir_friend_spec.rb
|
122
|
+
- spec/graph_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/melborne/dir_friend
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.1.9
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: '`DirFriend` is a tool for visualizing file directory.'
|
148
|
+
test_files:
|
149
|
+
- spec/dir_friend_spec.rb
|
150
|
+
- spec/graph_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
has_rdoc:
|