file-find 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -1
- data/lib/file/find.rb +26 -13
- data/test/tc_find.rb +6 -4
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
+
== 0.1.1 - 25-Apr-2007
|
2
|
+
* The default for name is now '*', i.e. everything.
|
3
|
+
* Fixed a bug where directories were not matched. Thanks go to Leslie Viljoen
|
4
|
+
for the spot.
|
5
|
+
* The size option now accepts strings with comparable operators. For example,
|
6
|
+
you can now look for files greater than 400 bytes with the string "> 400".
|
7
|
+
|
1
8
|
== 0.1.0 - 24-Apr-2007
|
2
|
-
* Initial release
|
9
|
+
* Initial release
|
data/lib/file/find.rb
CHANGED
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
|
3
3
|
class File::Find
|
4
4
|
# The version of this package
|
5
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.1'
|
6
6
|
|
7
7
|
# :stopdoc:
|
8
8
|
VALID_OPTIONS = %w/
|
@@ -62,11 +62,14 @@ class File::Find
|
|
62
62
|
attr_accessor :inum
|
63
63
|
|
64
64
|
# The name pattern used to limit file searches. The patterns that are legal
|
65
|
-
# for Dir.glob are legal here.
|
65
|
+
# for Dir.glob are legal here. The default is '*', i.e. everything.
|
66
66
|
#
|
67
67
|
attr_accessor :name
|
68
68
|
|
69
|
-
#
|
69
|
+
# If the value passed is an integer, this option limits searches to files
|
70
|
+
# that match the size, in bytes, exactly. If a string is passed, you can
|
71
|
+
# use the standard comparable operators to match files, e.g. ">= 200" would
|
72
|
+
# limit searches to files greater than or equal to 200 bytes.
|
70
73
|
#
|
71
74
|
attr_accessor :size
|
72
75
|
|
@@ -89,13 +92,13 @@ class File::Find
|
|
89
92
|
@group = nil
|
90
93
|
@follow = true
|
91
94
|
@inum = nil
|
92
|
-
@name = nil
|
93
95
|
@size = nil
|
94
96
|
@user = nil
|
95
97
|
|
96
98
|
validate_and_set_options(options) unless options.empty?
|
97
99
|
|
98
100
|
@path ||= Dir.pwd
|
101
|
+
@name ||= '*'
|
99
102
|
end
|
100
103
|
|
101
104
|
# Executes the find based on the rules you set for the File::Find object.
|
@@ -126,14 +129,15 @@ class File::Find
|
|
126
129
|
retry
|
127
130
|
end
|
128
131
|
|
132
|
+
glob = File.join(File.dirname(file), @name)
|
133
|
+
next unless Dir[glob].include?(file)
|
134
|
+
|
129
135
|
# Add directories back onto the list of paths to search unless
|
130
136
|
# they've already been added.
|
131
137
|
#
|
132
|
-
# TODO: Add depth handling.
|
133
138
|
if stat_info.directory?
|
134
139
|
unless paths.include?(file)
|
135
140
|
paths << file
|
136
|
-
next
|
137
141
|
end
|
138
142
|
end
|
139
143
|
|
@@ -163,14 +167,23 @@ class File::Find
|
|
163
167
|
end
|
164
168
|
end
|
165
169
|
|
166
|
-
|
167
|
-
glob = File.join(File.dirname(file), @name)
|
168
|
-
next unless Dir[glob].include?(file)
|
169
|
-
end
|
170
|
-
|
171
|
-
# TODO: Allow more flexible syntax here, e.g. "> 1024".
|
170
|
+
# Allow plain numbers, or strings for comparison operators.
|
172
171
|
if @size
|
173
|
-
|
172
|
+
if @size.is_a?(String)
|
173
|
+
regex = /^([><=]+)\s*?(\d+)$/
|
174
|
+
match = regex.match(@size)
|
175
|
+
|
176
|
+
if match.nil? || match.captures.include?(nil)
|
177
|
+
raise ArgumentError, "invalid size string: '#{@size}'"
|
178
|
+
end
|
179
|
+
|
180
|
+
operator = match.captures.first.strip
|
181
|
+
number = match.captures.last.strip.to_i
|
182
|
+
|
183
|
+
next unless stat_info.size.send(operator, number)
|
184
|
+
else
|
185
|
+
next unless stat_info.size == @size
|
186
|
+
end
|
174
187
|
end
|
175
188
|
|
176
189
|
if @user
|
data/test/tc_find.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
######################################################################
|
2
2
|
# tc_find.rb
|
3
3
|
#
|
4
|
-
# Test case for the File::Find package.
|
4
|
+
# Test case for the File::Find package. You should run this via the
|
5
|
+
# 'rake test' task.
|
5
6
|
######################################################################
|
6
|
-
Dir.chdir '..' if File.basename(Dir.pwd) == 'test'
|
7
|
-
$:.unshift File.join(Dir.pwd, 'lib')
|
8
|
-
|
9
7
|
require 'test/unit'
|
10
8
|
require 'fileutils'
|
11
9
|
require 'file/find'
|
@@ -23,6 +21,10 @@ class TC_File_Find < Test::Unit::TestCase
|
|
23
21
|
@rule1 = File::Find.new(:name => '*.rb')
|
24
22
|
end
|
25
23
|
|
24
|
+
def test_version
|
25
|
+
assert_equal('0.1.1', File::Find::VERSION)
|
26
|
+
end
|
27
|
+
|
26
28
|
def test_path
|
27
29
|
assert_respond_to(@rule1, :path)
|
28
30
|
assert_respond_to(@rule1, :path=)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: file-find
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-04-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-04-25 00:00:00 -06:00
|
8
8
|
summary: A better way to find files
|
9
9
|
require_paths:
|
10
10
|
- lib
|