class TMail::FilePort
Attributes
filename[R]
ident[R]
Public Class Methods
new( fname )
click to toggle source
Calls superclass method
# File lib/tmail/port.rb, line 50 def initialize( fname ) @filename = File.expand_path(fname) super() end
Public Instance Methods
==( other )
click to toggle source
# File lib/tmail/port.rb, line 59 def ==( other ) other.respond_to?(:filename) and @filename == other.filename end
Also aliased as: eql?
aopen( &block )
click to toggle source
# File lib/tmail/port.rb, line 90 def aopen( &block ) File.open(@filename, 'a', &block) end
copy_to( port )
click to toggle source
# File lib/tmail/port.rb, line 117 def copy_to( port ) if FilePort === port copy_file @filename, port.filename else File.open(@filename) {|r| port.wopen {|w| while s = r.sysread(4096) w.write << s end } } end end
Also aliased as: cp
hash()
click to toggle source
# File lib/tmail/port.rb, line 65 def hash @filename.hash end
inspect()
click to toggle source
# File lib/tmail/port.rb, line 69 def inspect "#<#{self.class}:#{@filename}>" end
move_to( port )
click to toggle source
# File lib/tmail/port.rb, line 106 def move_to( port ) begin File.link @filename, port.filename rescue Errno::EXDEV copy_to port end File.unlink @filename end
Also aliased as: mv
read_all()
click to toggle source
# File lib/tmail/port.rb, line 95 def read_all ropen {|f| return f.read } end
remove()
click to toggle source
# File lib/tmail/port.rb, line 102 def remove File.unlink @filename end
reproducible?()
click to toggle source
# File lib/tmail/port.rb, line 73 def reproducible? true end
ropen( &block )
click to toggle source
# File lib/tmail/port.rb, line 82 def ropen( &block ) File.open(@filename, &block) end
size()
click to toggle source
# File lib/tmail/port.rb, line 77 def size File.size @filename end
wopen( &block )
click to toggle source
# File lib/tmail/port.rb, line 86 def wopen( &block ) File.open(@filename, 'w', &block) end
Private Instance Methods
copy_file( src, dest )
click to toggle source
from fileutils.rb
# File lib/tmail/port.rb, line 135 def copy_file( src, dest ) st = r = w = nil File.open(src, 'rb') {|r| File.open(dest, 'wb') {|w| st = r.stat begin while true w.write r.sysread(st.blksize) end rescue EOFError end } } end