Class: Net::FTP
- Inherits:
-
Object
- Object
- Net::FTP
- Defined in:
- lib/razor/rake/ftp.rb
Instance Method Summary collapse
- #_chdir ⇒ Object
- #chdir(dir) ⇒ Object
- #directory?(name) ⇒ Boolean
- #entries ⇒ Object
- #put_contents(dir) ⇒ Object
- #put_r(file) ⇒ Object
- #rm_contents(dir) ⇒ Object
- #rm_r(file) ⇒ Object
Instance Method Details
#_chdir ⇒ Object
15 |
# File 'lib/razor/rake/ftp.rb', line 15 alias _chdir chdir |
#chdir(dir) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/razor/rake/ftp.rb', line 16 def chdir(dir) wd = (dir =~ /^\.?$/) if block_given? current = pwd wd or _chdir dir begin yield ensure wd or _chdir current end else wd or _chdir dir end end |
#directory?(name) ⇒ Boolean
5 6 7 8 9 |
# File 'lib/razor/rake/ftp.rb', line 5 def directory?(name) regexp = /#{name}$/ line = ls.find { |line| line =~ regexp } line or false and line[0] == ?d end |
#entries ⇒ Object
11 12 13 |
# File 'lib/razor/rake/ftp.rb', line 11 def entries nlst.reject { |e| e =~ /^(\.|\.\.)$/ } end |
#put_contents(dir) ⇒ Object
31 32 33 |
# File 'lib/razor/rake/ftp.rb', line 31 def put_contents(dir) Dir[dir+'/*'].each &method(:put_r) end |
#put_r(file) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/razor/rake/ftp.rb', line 35 def put_r(file) filename = File.basename file if File.directory? file mkdir filename chdir(filename) { put_contents file } else put file, filename end end |
#rm_contents(dir) ⇒ Object
45 46 47 48 49 |
# File 'lib/razor/rake/ftp.rb', line 45 def rm_contents(dir) chdir(dir) { entries.each &method(:rm_r) } end |
#rm_r(file) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/razor/rake/ftp.rb', line 51 def rm_r(file) if directory? file rm_contents file rmdir file else delete file end end |