Class: TMail::StringPort

Inherits:
Port
  • Object
show all
Defined in:
lib/tmail-pure/port.rb

Overview

StringPort

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ StringPort

Returns a new instance of StringPort.



275
276
277
278
# File 'lib/tmail-pure/port.rb', line 275

def initialize(str = '')
  @buffer = str
  super()
end

Instance Method Details

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



294
295
296
# File 'lib/tmail-pure/port.rb', line 294

def ==(other)
  other.is_a?(StringPort) and @buffer.equal?(other.string)
end

#aopen(&block) ⇒ Object



323
324
325
326
# File 'lib/tmail-pure/port.rb', line 323

def aopen(&block)
  @buffer ||= ''
  StringOutput.new(@buffer, &block)
end

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



334
335
336
337
338
# File 'lib/tmail-pure/port.rb', line 334

def copy_to(port)
  port.wopen {|f|
    f.write @buffer
  }
end

#hashObject



300
301
302
# File 'lib/tmail-pure/port.rb', line 300

def hash
  @buffer.object_id.hash
end

#inspectObject



304
305
306
# File 'lib/tmail-pure/port.rb', line 304

def inspect
  "#<#{self.class}:id=#{sprintf '0x%x', @buffer.object_id}>"
end

#move_to(port) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
# File 'lib/tmail-pure/port.rb', line 342

def move_to(port)
  if port.is_a?(StringPort)
    tmp = @buffer
    port.instance_eval {
      @buffer = tmp
    }
  else
    copy_to port
  end
  remove
end

#removeObject Also known as: rm



328
329
330
# File 'lib/tmail-pure/port.rb', line 328

def remove
  @buffer = nil
end

#reproducible?Boolean

Returns:

  • (Boolean)


308
309
310
# File 'lib/tmail-pure/port.rb', line 308

def reproducible?
  true
end

#ropen(&block) ⇒ Object

Raises:

  • (Errno::ENOENT)


312
313
314
315
316
# File 'lib/tmail-pure/port.rb', line 312

def ropen(&block)
  # FIXME: Should we raise ENOENT?
  raise Errno::ENOENT, "#{inspect} is already removed" unless @buffer
  StringInput.open(@buffer, &block)
end

#sizeObject



290
291
292
# File 'lib/tmail-pure/port.rb', line 290

def size
  @buffer.size
end

#stringObject



280
281
282
# File 'lib/tmail-pure/port.rb', line 280

def string
  @buffer
end

#to_sObject Also known as: read_all



284
285
286
# File 'lib/tmail-pure/port.rb', line 284

def to_s
  @buffer.dup
end

#wopen(&block) ⇒ Object



318
319
320
321
# File 'lib/tmail-pure/port.rb', line 318

def wopen(&block)
  @buffer = ''
  StringOutput.new(@buffer, &block)
end