Sha256: 8b78737511895e85b5c31f23723a491bbf9811ba17c732c994870acdfcdadd7a

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module DataObjects
  # Abstract class to read rows from a query result
  class Reader
    include Enumerable

    # Return the array of field names
    def fields
      raise NotImplementedError
    end

    # Return the array of field values for the current row. Not legal after next! has returned false or before it's been called
    def values
      raise NotImplementedError
    end

    # Close the reader discarding any unread results.
    def close
      raise NotImplementedError
    end

    # Discard the current row (if any) and read the next one (returning true), or return nil if there is no further row.
    def next!
      raise NotImplementedError
    end

    # Return the number of fields in the result set.
    def field_count
      raise NotImplementedError
    end

    # Yield each row to the given block as a Hash
    def each
      begin
        while next!
          row = {}
          fields.each_with_index { |field, index| row[field] = values[index] }
          yield row
        end
      ensure
        close
      end
      self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbf-data_objects-0.11.0 lib/data_objects/reader.rb
sbf-data_objects-0.10.17 lib/data_objects/reader.rb