net-ftp-list 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +3 -2
- data/Rakefile +1 -1
- data/lib/net/ftp/list.rb +5 -26
- data/test/test_net_ftp_list.rb +3 -3
- metadata +2 -2
data/README.txt
CHANGED
@@ -28,8 +28,9 @@ See the RFC for more guff on LIST and NLST: http://www.ietf.org/rfc/rfc0959.txt
|
|
28
28
|
require 'net/ftp/list'
|
29
29
|
|
30
30
|
ftp = Net::FTP.open('somehost.com', 'user', 'pass')
|
31
|
-
ftp.
|
32
|
-
|
31
|
+
ftp.list('/some/path') do |e|
|
32
|
+
entry = Net::FTP::List.parse(e)
|
33
|
+
|
33
34
|
# Ignore everything that's not a file (so symlinks, directories and devices etc.)
|
34
35
|
next unless entry.file?
|
35
36
|
|
data/Rakefile
CHANGED
data/lib/net/ftp/list.rb
CHANGED
@@ -10,17 +10,15 @@ module Net #:nodoc:
|
|
10
10
|
|
11
11
|
# Parse FTP LIST responses.
|
12
12
|
#
|
13
|
-
# Mixin the +Net::FTP::List+ module and subsequent calls to the Net::FTP +list+, +ls+ or +dir+ methods will be
|
14
|
-
# parsed by the LIST parser as best it can.
|
15
|
-
#
|
16
13
|
# == Creation
|
17
14
|
#
|
18
15
|
# require 'net/ftp' # Not really required but I like to list dependencies sometimes.
|
19
16
|
# require 'net/ftp/list'
|
20
17
|
#
|
21
18
|
# ftp = Net::FTP.open('somehost.com', 'user', 'pass')
|
22
|
-
# ftp.
|
23
|
-
#
|
19
|
+
# ftp.list('/some/path') do |e|
|
20
|
+
# entry = Net::FTP::List.parse(e)
|
21
|
+
#
|
24
22
|
# # Ignore everything that's not a file (so symlinks, directories and devices etc.)
|
25
23
|
# next unless entry.file?
|
26
24
|
#
|
@@ -34,29 +32,10 @@ module Net #:nodoc:
|
|
34
32
|
# None at this time. At worst you'll end up with an Net::FTP::List::Unknown instance which won't have any extra
|
35
33
|
# useful information. Methods like <tt>dir?</tt>, <tt>file?</tt> and <tt>symlink?</tt> will all return +false+.
|
36
34
|
module List
|
37
|
-
|
38
|
-
|
39
|
-
class << klass
|
40
|
-
|
41
|
-
alias_method :raw_list, :list
|
42
|
-
def list(*args, &block)
|
43
|
-
if block
|
44
|
-
raw_list(*args) do |raw|
|
45
|
-
Net::FTP::List::Parser.parse(raw)
|
46
|
-
yield raw
|
47
|
-
end
|
48
|
-
else
|
49
|
-
raw_list(*args).map do |raw|
|
50
|
-
Net::FTP::List::Parser.parse(raw)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
35
|
+
def self.parse(*args)
|
36
|
+
Parser.parse(*args)
|
56
37
|
end
|
57
|
-
|
58
38
|
end
|
59
|
-
|
60
39
|
end
|
61
40
|
end
|
62
41
|
|
data/test/test_net_ftp_list.rb
CHANGED
@@ -4,8 +4,8 @@ require 'net/ftp/list'
|
|
4
4
|
class TestNetFTPList < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@dir = Net::FTP::List
|
8
|
-
@file = Net::FTP::List
|
7
|
+
@dir = Net::FTP::List.parse('drwxr-xr-x 4 user group 4096 Dec 10 20:23 etc')
|
8
|
+
@file = Net::FTP::List.parse('-rw-r--r-- 1 root other 531 Jan 29 03:26 README')
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_parse_new
|
@@ -14,7 +14,7 @@ class TestNetFTPList < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_rubbish_lines
|
17
|
-
assert_instance_of Net::FTP::List::Unknown, Net::FTP::List
|
17
|
+
assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_ruby_unix_like_dir
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: net-ftp-list
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2008-01-
|
6
|
+
version: "0.5"
|
7
|
+
date: 2008-01-17 00:00:00 +11:00
|
8
8
|
summary: Parse FTP LIST command output.
|
9
9
|
require_paths:
|
10
10
|
- lib
|