22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/evesync/ipc/data.rb', line 22
def self.unpack(message)
unless message.is_a? String
raise "IPC ERROR message #{message} must be of type String"
end
begin
hash = JSON.parse(message)
rescue JSON::ParseError => e
Log.fatal("IPC ERROR Unable to parse message #{message}")
raise e
end
begin
Log.debug("IPC Accepted basic hash #{hash}")
cl = Object.const_get hash['type']
rescue NameError => e
Log.fatal("Unsupported basic type #{hash['type']}")
raise e
end
unless cl.respond_to? :from_hash
err_msg = "IPC ERROR Class #{cl} must implement `self.from_hash'"
Log.fatal(err_msg)
raise err_msg
end
cl.from_hash hash
end
|