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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa7bb1977ab2096ec7285d4812f11b3a17291bb8
4
- data.tar.gz: fad70081f893281aef5b38c136684d877ef70de9
3
+ metadata.gz: 9a765043c125a1efed87ec20594becf2c5c3cf18
4
+ data.tar.gz: 81383aa7939d8c715b1c3246d543fb1c1b5c5ddf
5
5
  SHA512:
6
- metadata.gz: f25be97b601b4f83effad5b82647cb2025c36fb1552f8a2f4b98e41fa2b7f1b1d0f07fb947e02c116029f3ce540e3cb0126133ceaa182dc4f5464b65d59443af
7
- data.tar.gz: 95fe6a182a8ec999ae56ef98ca0148b7721caa45bcd161f3a9d9e93384d468e80267b9f7d81cacbae9196a6010759bc68a16f453fe2445616e71a912f6fea45e
6
+ metadata.gz: 20bbe681c5115ace99a3d94a32fabe0cd8c368989ba4c0debdad0327f4e9fb9cad79e0c2f6ebc565741dc07125812f81671cf0ebdc5d74d16b88ba8da5459904
7
+ data.tar.gz: aba339f7d73bac23fb2181e81afb73a11676bd3d3a65612f4ed0dcb56282da29fdc04863d0b19235b64afa0012e6faaf585bf2cffe5731c291b6252da3dce8ea
@@ -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
@@ -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
 
@@ -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
- @entries << Any.new(ent, level:level+1, depth:depth-1)
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
@@ -1,3 +1,3 @@
1
1
  module DirFriend
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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.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-10-31 00:00:00.000000000 Z
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.9
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.'