class Relaxo::QueryServer::Shell
A simple wrapper that reads and writes objects using JSON serialization to the given ‘input` and `output` `IO`s.
Attributes
input[R]
output[R]
Public Class Methods
new(input, output)
click to toggle source
# File lib/relaxo/query_server/shell.rb, line 28 def initialize(input, output) @input = input @output = output end
Public Instance Methods
read_object()
click to toggle source
Read a JSON serialised object from ‘input`.
# File lib/relaxo/query_server/shell.rb, line 37 def read_object JSON.parse @input.readline end
run() { |command| ... }
click to toggle source
Read commands from ‘input`, execute them and then write out the results.
# File lib/relaxo/query_server/shell.rb, line 48 def run begin while true command = read_object result = yield command write_object(result) end rescue EOFError # Finish... end end
write_object(object)
click to toggle source
Write a JSON serialized object to ‘output`.
# File lib/relaxo/query_server/shell.rb, line 42 def write_object object @output.puts object.to_json @output.flush end