Class: TMail::FilePort

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



28
29
30
31
# File 'lib/tmail-pure/port.rb', line 28

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

Instance Attribute Details

#pathObject (readonly) Also known as: filename, ident

Returns the value of attribute path.



33
34
35
# File 'lib/tmail-pure/port.rb', line 33

def path
  @path
end

Instance Method Details

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



38
39
40
# File 'lib/tmail-pure/port.rb', line 38

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

#aopen(&block) ⇒ Object



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

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

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



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

def copy_to(port)
  if port.is_a?(FilePort)
    copy_file @path, port.path
  else
    File.open(@path) {|r|
      port.wopen {|w|
        while s = r.sysread(4096)
          w.write << s
        end
      }
    }
  end
end

#hashObject



44
45
46
# File 'lib/tmail-pure/port.rb', line 44

def hash
  @path.hash
end

#inspectObject



48
49
50
# File 'lib/tmail-pure/port.rb', line 48

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

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



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

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

#read_allObject



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

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

#removeObject



81
82
83
# File 'lib/tmail-pure/port.rb', line 81

def remove
  File.unlink @path
end

#reproducible?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/tmail-pure/port.rb', line 52

def reproducible?
  true
end

#ropen(&block) ⇒ Object



61
62
63
# File 'lib/tmail-pure/port.rb', line 61

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

#sizeObject



56
57
58
# File 'lib/tmail-pure/port.rb', line 56

def size
  File.size(@path)
end

#wopen(&block) ⇒ Object



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

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