Class: DataObjects::Reader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/data_objects/reader.rb

Overview

Abstract class to read rows from a query result

Instance Method Summary collapse

Instance Method Details

#closeObject

Close the reader discarding any unread results.

Raises:



17
18
19
# File 'lib/data_objects/reader.rb', line 17

def close
  raise NotImplementedError
end

#eachObject

Yield each row to the given block as a Hash



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/data_objects/reader.rb', line 32

def each
  begin
    while next!
      row = {}
      fields.each_with_index { |field, index| row[field] = values[index] }
      yield row
    end
  ensure
    close
  end
  self
end

#field_countObject

Return the number of fields in the result set.

Raises:



27
28
29
# File 'lib/data_objects/reader.rb', line 27

def field_count
  raise NotImplementedError
end

#fieldsObject

Return the array of field names

Raises:



7
8
9
# File 'lib/data_objects/reader.rb', line 7

def fields
  raise NotImplementedError
end

#next!Object

Discard the current row (if any) and read the next one (returning true), or return nil if there is no further row.

Raises:



22
23
24
# File 'lib/data_objects/reader.rb', line 22

def next!
  raise NotImplementedError
end

#valuesObject

Return the array of field values for the current row. Not legal after next! has returned false or before it’s been called

Raises:



12
13
14
# File 'lib/data_objects/reader.rb', line 12

def values
  raise NotImplementedError
end