class T2Server::PortValue

A class to represent an output port data value.



The URI reference of this port value as a String.


The size (in bytes) of the port value.


The mime type of this port value as a String.

Public Instance Methods

error → string click to toggle source

Return the error message for this value, or nil if it is not an error.

# File lib/t2-server/port.rb, line 429
def error
error? → bool click to toggle source

Does this port represent an error?

# File lib/t2-server/port.rb, line 421
def error?
inspect → string click to toggle source

Return a printable representation of this port value for debugging purposes.

# File lib/t2-server/port.rb, line 441
def inspect
  @@to_s.bind(self).call.sub!(%r>\z/) { " @value=#{value.inspect}, " +
    "@type=#{type.inspect}, @size=#{size.inspect}>"
value → obj click to toggle source
value(range) → obj

Return the value of this port. It is downloaded from the server if it has not already been retrieved. If a range is specified then just that portion of the value is downloaded and returned. If no range is specified then the whole value is downloaded and returned.

All downloaded data is cached and not downloaded a second time if the same or similar ranges are requested.

# File lib/t2-server/port.rb, line 370
def value(range = 0...@size)
  return nil if error?
  return "" if @type == "application/x-empty"
  return @value if range == :debug

  # check that the range provided is sensible
  range = 0..range.max if range.min < 0
  range = range.min...@size if range.max >= @size

  need = fill(@vgot, range)
  case need.length
  when 0
    # we already have all the data we need, just return the right bit.
    # @vgot cannot be nil here and must fully encompass range.
    ret_range = (range.min - @vgot.min)..(range.max - @vgot.min)
  when 1
    # we either have some data, at one end of range or either side of it,
    # or none. @vgot can be nil here.
    # In both cases we download what we need.
    new_data =, need[0])
    if @vgot.nil?
      # this is the only data we have, return it all.
      @vgot = range
      @value = new_data
      # add the new data to the correct end of the data we have, then
      # return the range requested.
      if range.max <= @vgot.max
        @vgot = range.min..@vgot.max
        @value = new_data + @value
        @vgot = @vgot.min..range.max
        @value = @value + new_data
        @value[(range.min - @vgot.min)..@vgot.max]
  when 2
    # we definitely have some data and it is in the middle of the
    # range requested. @vgot cannot be nil here.
    @vgot = range
    @value =, need[0]) + @value +, need[1])