class Relaxo::QueryServer::ListRenderer

Supports the ‘list` action which consumes rows and outputs encoded text in chunks.

Public Class Methods

new(context, function) click to toggle source
Calls superclass method
# File lib/relaxo/query_server/designer.rb, line 59
def initialize(context, function)
        super(context, function)
        
        @started = false
        @fetched_row = false
        @start_response = {:headers => {}}
        @chunks = []
end

Public Instance Methods

each() { |row| ... } click to toggle source
# File lib/relaxo/query_server/designer.rb, line 82
def each
        while row = get_row
                yield row
        end
end
flush() click to toggle source
# File lib/relaxo/query_server/designer.rb, line 110
def flush
        if @started
                @context.shell.write_object ["chunks", @chunks]
        else
                @context.shell.write_object ["start", @chunks, @start_response]
                
                @started = true
        end
        
        @chunks = []
end
get_row() click to toggle source
# File lib/relaxo/query_server/designer.rb, line 88
def get_row
        flush
        
        row = @context.shell.read_object
        @fetched_row = true
        
        case command = row[0]
        when "list_row"
                row[1]
        when "list_end"
                false
        else
                raise RuntimeError.new("Input is not a row!")
        end
end
run(head, request) click to toggle source
Calls superclass method
# File lib/relaxo/query_server/designer.rb, line 68
def run(head, request)
        super(head, request)
        
        # Ensure that at least one row is read from input:
        get_row unless @fetched_row
        
        return ["end", @chunks]
end
send(chunk) click to toggle source
# File lib/relaxo/query_server/designer.rb, line 77
def send(chunk)
        @chunks << chunk
        false
end
start(response) click to toggle source
# File lib/relaxo/query_server/designer.rb, line 104
def start(response)
        raise RuntimeError.new("List already started!") if @started
        
        @start_response = response
end