Class: TMail::FilePort
Overview
FilePort
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
(also: #filename, #ident)
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #aopen(&block) ⇒ Object
- #copy_to(port) ⇒ Object (also: #cp)
- #hash ⇒ Object
-
#initialize(fname) ⇒ FilePort
constructor
A new instance of FilePort.
- #inspect ⇒ Object
- #move_to(port) ⇒ Object (also: #mv)
- #read_all ⇒ Object
- #remove ⇒ Object
- #reproducible? ⇒ Boolean
- #ropen(&block) ⇒ Object
- #size ⇒ Object
- #wopen(&block) ⇒ Object
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.(fname) super() end |
Instance Attribute Details
#path ⇒ Object (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 |
#hash ⇒ Object
44 45 46 |
# File 'lib/tmail-pure/port.rb', line 44 def hash @path.hash end |
#inspect ⇒ Object
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_all ⇒ Object
74 75 76 77 78 |
# File 'lib/tmail-pure/port.rb', line 74 def read_all ropen {|f| return f.read } end |
#remove ⇒ Object
81 82 83 |
# File 'lib/tmail-pure/port.rb', line 81 def remove File.unlink @path end |
#reproducible? ⇒ 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 |
#size ⇒ Object
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 |