Class TMail::FilePort
In: lib/tmail/port.rb
Parent: Port

Methods

==   aopen   copy_to   cp   eql?   hash   inspect   move_to   mv   new   read_all   remove   reproducible?   ropen   size   wopen  

External Aliases

path -> filename
path -> ident

Attributes

path  [R] 

Public Class methods

[Source]

# File lib/tmail/port.rb, line 28
    def initialize(fname)
      @path = File.expand_path(fname)
      super()
    end

Public Instance methods

[Source]

# File lib/tmail/port.rb, line 38
    def ==(other)
      other.respond_to?(:path) and @path == other.path
    end

[Source]

# File lib/tmail/port.rb, line 69
    def aopen(&block)
      File.open(@path, 'a', &block)
    end

[Source]

# File lib/tmail/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
cp(port)

Alias for copy_to

eql?(other)

Alias for #==

[Source]

# File lib/tmail/port.rb, line 44
    def hash
      @path.hash
    end

[Source]

# File lib/tmail/port.rb, line 48
    def inspect
      "#<#{self.class} #{@path}>"
    end

[Source]

# File lib/tmail/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
mv(port)

Alias for move_to

[Source]

# File lib/tmail/port.rb, line 74
    def read_all
      ropen {|f|
        return f.read
      }
    end

[Source]

# File lib/tmail/port.rb, line 81
    def remove
      File.unlink @path
    end

[Source]

# File lib/tmail/port.rb, line 52
    def reproducible?
      true
    end

[Source]

# File lib/tmail/port.rb, line 61
    def ropen(&block)
      File.open(@path, &block)
    end

[Source]

# File lib/tmail/port.rb, line 56
    def size
      File.size(@path)
    end

[Source]

# File lib/tmail/port.rb, line 65
    def wopen(&block)
      File.open(@path, 'w', &block)
    end

[Validate]