Class: TMail::FilePort

Inherits:
Port
  • Object
show all
Defined in:
lib/action_mailer/vendor/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.



48
49
50
51
# File 'lib/action_mailer/vendor/tmail/port.rb', line 48

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.



53
54
55
# File 'lib/action_mailer/vendor/tmail/port.rb', line 53

def filename
  @filename
end

Instance Method Details

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



57
58
59
# File 'lib/action_mailer/vendor/tmail/port.rb', line 57

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

#aopen(&block) ⇒ Object



88
89
90
# File 'lib/action_mailer/vendor/tmail/port.rb', line 88

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

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



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/action_mailer/vendor/tmail/port.rb', line 115

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



63
64
65
# File 'lib/action_mailer/vendor/tmail/port.rb', line 63

def hash
  @filename.hash
end

#inspectObject



67
68
69
# File 'lib/action_mailer/vendor/tmail/port.rb', line 67

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

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



104
105
106
107
108
109
110
111
# File 'lib/action_mailer/vendor/tmail/port.rb', line 104

def move_to( port )
  begin
    File.link @filename, port.filename
  rescue Errno::EXDEV
    copy_to port
  end
  File.unlink @filename
end

#read_allObject



93
94
95
96
97
# File 'lib/action_mailer/vendor/tmail/port.rb', line 93

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

#removeObject



100
101
102
# File 'lib/action_mailer/vendor/tmail/port.rb', line 100

def remove
  File.unlink @filename
end

#reproducible?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/action_mailer/vendor/tmail/port.rb', line 71

def reproducible?
  true
end

#ropen(&block) ⇒ Object



80
81
82
# File 'lib/action_mailer/vendor/tmail/port.rb', line 80

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

#sizeObject



75
76
77
# File 'lib/action_mailer/vendor/tmail/port.rb', line 75

def size
  File.size @filename
end

#wopen(&block) ⇒ Object



84
85
86
# File 'lib/action_mailer/vendor/tmail/port.rb', line 84

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