Class: DataObjects::Reader
- Inherits:
-
Object
- Object
- DataObjects::Reader
- Includes:
- Enumerable
- Defined in:
- lib/data_objects/reader.rb
Overview
Abstract class to read rows from a query result
Instance Method Summary collapse
-
#close ⇒ Object
Close the reader discarding any unread results.
-
#each ⇒ Object
Yield each row to the given block as a Hash.
-
#field_count ⇒ Object
Return the number of fields in the result set.
-
#fields ⇒ Object
Return the array of field names.
-
#next! ⇒ Object
Discard the current row (if any) and read the next one (returning true), or return nil if there is no further row.
-
#values ⇒ Object
Return the array of field values for the current row.
Instance Method Details
#close ⇒ Object
Close the reader discarding any unread results.
18 19 20 |
# File 'lib/data_objects/reader.rb', line 18 def close raise NotImplementedError.new end |
#each ⇒ Object
Yield each row to the given block as a Hash
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/data_objects/reader.rb', line 33 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_count ⇒ Object
Return the number of fields in the result set.
28 29 30 |
# File 'lib/data_objects/reader.rb', line 28 def field_count raise NotImplementedError.new end |
#fields ⇒ Object
Return the array of field names
8 9 10 |
# File 'lib/data_objects/reader.rb', line 8 def fields raise NotImplementedError.new 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.
23 24 25 |
# File 'lib/data_objects/reader.rb', line 23 def next! raise NotImplementedError.new end |
#values ⇒ Object
Return the array of field values for the current row. Not legal after next! has returned false or before it’s been called
13 14 15 |
# File 'lib/data_objects/reader.rb', line 13 def values raise NotImplementedError.new end |