Class: TMail::FilePort

Inherits:
Port show all
Defined in:
lib/tmail/port.rb

Overview

FilePort

Direct Known Subclasses

MaildirPort, MhPort

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname) ⇒ FilePort

Returns a new instance of FilePort.



50
51
52
53
# File 'lib/tmail/port.rb', line 50

def initialize( fname )
  @filename = File.expand_path(fname)
  super()
end

Instance Attribute Details

#filenameObject (readonly) Also known as: ident

Returns the value of attribute filename.



55
56
57
# File 'lib/tmail/port.rb', line 55

def filename
  @filename
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



59
60
61
# File 'lib/tmail/port.rb', line 59

def ==( other )
  other.respond_to?(:filename) and @filename == other.filename
end

#aopen(&block) ⇒ Object



90
91
92
# File 'lib/tmail/port.rb', line 90

def aopen( &block )
  File.open(@filename, 'a', &block)
end

#copy_to(port) ⇒ Object Also known as: cp



117
118
119
120
121
122
123
124
125
126
127
128
# 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

#hashObject



65
66
67
# File 'lib/tmail/port.rb', line 65

def hash
  @filename.hash
end

#inspectObject



69
70
71
# File 'lib/tmail/port.rb', line 69

def inspect
  "#<#{self.class}:#{@filename}>"
end

#move_to(port) ⇒ Object Also known as: mv



106
107
108
109
110
111
112
113
# 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

#read_allObject



95
96
97
98
99
# File 'lib/tmail/port.rb', line 95

def read_all
  ropen {|f|
      return f.read
  }
end

#removeObject



102
103
104
# File 'lib/tmail/port.rb', line 102

def remove
  File.unlink @filename
end

#reproducible?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/tmail/port.rb', line 73

def reproducible?
  true
end

#ropen(&block) ⇒ Object



82
83
84
# File 'lib/tmail/port.rb', line 82

def ropen( &block )
  File.open(@filename, &block)
end

#sizeObject



77
78
79
# File 'lib/tmail/port.rb', line 77

def size
  File.size @filename
end

#wopen(&block) ⇒ Object



86
87
88
# File 'lib/tmail/port.rb', line 86

def wopen( &block )
  File.open(@filename, 'w', &block)
end