Class: Terastream::Query::ResultSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/terastream/query/result_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_set, formatter = Terastream::JsonBuilder.new, destination = nil) ⇒ ResultSet

Returns a new instance of ResultSet.



14
15
16
17
18
19
20
21
# File 'lib/terastream/query/result_set.rb', line 14

def initialize(record_set, formatter = Terastream::JsonBuilder.new, destination = nil)
  @record_set = record_set
  @metadata = ResultSetMetadata.new(record_set)
  @formatter = formatter
  @output = destination || default_output
  @_results = nil
  @formatter.app(self)
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



10
11
12
# File 'lib/terastream/query/result_set.rb', line 10

def formatter
  @formatter
end

#headersObject

Returns the value of attribute headers.



10
11
12
# File 'lib/terastream/query/result_set.rb', line 10

def headers
  @headers
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/terastream/query/result_set.rb', line 10

def output
  @output
end

#record_setObject

Returns the value of attribute record_set.



10
11
12
# File 'lib/terastream/query/result_set.rb', line 10

def record_set
  @record_set
end

#resultsObject

Returns the value of attribute results.



10
11
12
# File 'lib/terastream/query/result_set.rb', line 10

def results
  @results
end

Instance Method Details

#buildObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/terastream/query/result_set.rb', line 27

def build
  if formatter.respond_to?(:init)
    @output << formatter.init
  end

  while row = @record_set.next
    @output << formatter.call
  end
  @output.send(:complete!) if @output.respond_to?(:complete!)
  @output if @output.instance_of?(Array)
end

#each(&block) ⇒ Object



39
40
41
42
43
# File 'lib/terastream/query/result_set.rb', line 39

def each(&block)
  results.each do |result|
    yield result
  end
end