dir_friend 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dir_friend/any.rb +2 -2
- data/lib/dir_friend/command.rb +4 -2
- data/lib/dir_friend/d.rb +4 -2
- data/lib/dir_friend/version.rb +1 -1
- data/spec/dir_friend_spec.rb +21 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a765043c125a1efed87ec20594becf2c5c3cf18
|
4
|
+
data.tar.gz: 81383aa7939d8c715b1c3246d543fb1c1b5c5ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20bbe681c5115ace99a3d94a32fabe0cd8c368989ba4c0debdad0327f4e9fb9cad79e0c2f6ebc565741dc07125812f81671cf0ebdc5d74d16b88ba8da5459904
|
7
|
+
data.tar.gz: aba339f7d73bac23fb2181e81afb73a11676bd3d3a65612f4ed0dcb56282da29fdc04863d0b19235b64afa0012e6faaf585bf2cffe5731c291b6252da3dce8ea
|
data/lib/dir_friend/any.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module DirFriend
|
2
2
|
class Any
|
3
|
-
def self.new(f, level:0, depth:Float::MAX.to_i)
|
3
|
+
def self.new(f, level:0, depth:Float::MAX.to_i, exclude:[])
|
4
4
|
if File.directory?(f)
|
5
|
-
D.new(f, level:level, depth:depth)
|
5
|
+
D.new(f, level:level, depth:depth, exclude:exclude)
|
6
6
|
else
|
7
7
|
F.new(f, level:level)
|
8
8
|
end
|
data/lib/dir_friend/command.rb
CHANGED
@@ -25,16 +25,18 @@ module DirFriend
|
|
25
25
|
option :global, aliases:"-g"
|
26
26
|
option :nodes, aliases:"-n"
|
27
27
|
option :edges, aliases:"-e"
|
28
|
-
option :save, aliases:"-s", default:'a'
|
28
|
+
option :save, aliases:"-s", default:'a', desc:"Save filename"
|
29
29
|
option :depth, aliases:"-d", default:9
|
30
30
|
option :with_open, aliases:"-o", default: true, type: :boolean
|
31
31
|
option :theme, aliases:"-t"
|
32
|
+
option :exclude, aliases:"-x", desc:"Specify directories for exclude with comma separated values"
|
32
33
|
def dot(path)
|
33
34
|
opt = options.to_keysym_hash
|
34
35
|
save_path = opt.delete(:save)
|
36
|
+
exclude = (ex=opt.delete(:exclude)) ? ex.split(',') : []
|
35
37
|
opt = opt_parser(opt)
|
36
38
|
|
37
|
-
dir = D.new(path, depth:options[:depth].to_i)
|
39
|
+
dir = D.new(path, depth:options[:depth].to_i, exclude:exclude)
|
38
40
|
dir.to_dot(opt).save(save_path)
|
39
41
|
puts "'#{save_path}.dot' created in the current directory."
|
40
42
|
|
data/lib/dir_friend/d.rb
CHANGED
@@ -10,9 +10,10 @@ module DirFriend
|
|
10
10
|
class D < F
|
11
11
|
include Enumerable
|
12
12
|
attr_reader :entries
|
13
|
-
def initialize(name='.', level:0, depth:Float::MAX.to_i)
|
13
|
+
def initialize(name='.', level:0, depth:Float::MAX.to_i, exclude:[])
|
14
14
|
super(name, level:level)
|
15
15
|
@entries = []
|
16
|
+
@exclude = exclude.map { |ex| File.expand_path ex }
|
16
17
|
build(depth) if depth >= 1
|
17
18
|
self
|
18
19
|
end
|
@@ -70,7 +71,8 @@ module DirFriend
|
|
70
71
|
def build(depth)
|
71
72
|
entries = Dir[File.join(path, '*')]
|
72
73
|
entries.each do |ent|
|
73
|
-
|
74
|
+
next if @exclude.include?(File.expand_path ent)
|
75
|
+
@entries << Any.new(ent, level:level+1, depth:depth-1, exclude:@exclude)
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
data/lib/dir_friend/version.rb
CHANGED
data/spec/dir_friend_spec.rb
CHANGED
@@ -137,6 +137,27 @@ describe DirFriend do
|
|
137
137
|
expect(test).to be_true
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
context 'exclude specific directories' do
|
142
|
+
before(:each) do
|
143
|
+
%w(A/J).each { |d| Dir.mkdir d }
|
144
|
+
%w(A/J/k A/J/l).each { |f| File.write(f, '') }
|
145
|
+
@dx = DirFriend::D.new('A', exclude:['A/D/G', 'A/J'])
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#entries' do
|
149
|
+
it 'returns entries except the excluded ones' do
|
150
|
+
expect(@dx.entries.map(&:name).sort).to eq %w(D a b c)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#each' do
|
155
|
+
it 'iterates whole files except the excluded ones' do
|
156
|
+
ent = @dx.map(&:name).sort
|
157
|
+
expect(ent).to eq %w(D a b c e f)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
140
161
|
end
|
141
162
|
|
142
163
|
describe DirFriend::Any do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir_friend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gviz
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.1.
|
150
|
+
rubygems_version: 2.1.11
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: '`DirFriend` is a tool for generating a DOT file which represent file directories.'
|