Class: RemoteRuby::Unmarshaler

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/unmarshaler.rb

Overview

Unmarshals variables from given stream

Constant Summary collapse

UnmarshalError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(stream, terminator = nil) ⇒ Unmarshaler

Returns a new instance of Unmarshaler.


6
7
8
9
# File 'lib/remote_ruby/unmarshaler.rb', line 6

def initialize(stream, terminator = nil)
  @stream = stream
  @terminator = terminator
end

Instance Method Details

#unmarshalObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/remote_ruby/unmarshaler.rb', line 11

def unmarshal
  res = {}

  until stream.eof?
    line = stream.readline

    break if terminator && line == terminator

    var = read_var(line)
    res[var.first] = var[1]
  end

  res
end