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.



29
30
31
32
# File 'lib/action_mailer/vendor/tmail/port.rb', line 29

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.



34
35
36
# File 'lib/action_mailer/vendor/tmail/port.rb', line 34

def filename
  @filename
end

Instance Method Details

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



38
39
40
# File 'lib/action_mailer/vendor/tmail/port.rb', line 38

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

#aopen(&block) ⇒ Object



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

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

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



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/action_mailer/vendor/tmail/port.rb', line 96

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



44
45
46
# File 'lib/action_mailer/vendor/tmail/port.rb', line 44

def hash
  @filename.hash
end

#inspectObject



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

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

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



85
86
87
88
89
90
91
92
# File 'lib/action_mailer/vendor/tmail/port.rb', line 85

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

#read_allObject



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

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

#removeObject



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

def remove
  File.unlink @filename
end

#reproducible?Boolean

Returns:

  • (Boolean)


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

def reproducible?
  true
end

#ropen(&block) ⇒ Object



61
62
63
# File 'lib/action_mailer/vendor/tmail/port.rb', line 61

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

#sizeObject



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

def size
  File.size @filename
end

#wopen(&block) ⇒ Object



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

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