Content preview: Hi, I tried to write a script to find all empty
directories
in a subversion checkout. In my view there were two main problems to
solve:
1) empty directories also contain .svn control directories […]
Content analysis details: (-2.9 points, 5.0 required)
pts rule name description
-1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP
-1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%
[score: 0.0000]
X-Cloudmark-Analysis: v=1.1
cv=FXfX1j538S0toKVv4AeTokQJ/Dr7x98IW2CddS+R9NE= c=1 sm=0
a=4Og3Em56ZtMA:10 a=IkcTkHD0fZMA:10 a=NEAV23lmAAAA:8
a=AkrA4ZvoYTkGoRutxRQA:9 a=_j8hiipnOi44SOWC491EbzjUegsA:4
a=QEXdDO2ut3YA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Precedence: bulk
Lines: 52
List-Id: ruby-talk.ruby-lang.org
List-Software: fml [fml 4.0.3 release (20011202/4.0.3)]
List-Post: mailto:[email protected]
List-Owner: mailto:[email protected]
List-Help: mailto:[email protected]?body=help
List-Unsubscribe: mailto:[email protected]?body=unsubscribe
Received-SPF: none (Address does not pass the Sender Policy Framework)
SPF=FROM;
[email protected];
remoteip=::ffff:221.186.184.68;
remotehost=carbon.ruby-lang.org;
helo=carbon.ruby-lang.org;
receiver=eq4.andreas-s.net;
Hi,
I tried to write a script to find all empty directories in a subversion
checkout. In my view there were two main problems to solve:
-
empty directories also contain .svn control directories
-
directories containing only further empty directories should be
detected as such too.
I came up with https://gist.github.com/852051 and on my simple tests so
far it worked well. I’d like to get feedback on the code and how I used
certain idioms, or rather, miss-used certain idioms or areas where I can
improve it “the ruby way”.
For example, I’m not really fond of the big case statement in the fourth
loop block:
dirs_count[dir] =
Dir.entries(dir).collect { |e|
case e
when '.svn'
nil
when '.'
nil
when '..'
nil
else
e
end
}.compact.count
Seems pretty redundant to me, in other languages I’d have written e.g.
switch(e) {
case ‘.svn’:
case ‘.’:
case ‘…’:
return nil;
default:
return e;
}
But I’m not sure how to apply that in ruby and I also think that these
could be improved anyway.
I’m sure a trained mind can spot other areas for improvement, I’m glad
for any suggestions!
thanks,
- Markus