Class: RDBI::Result::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/rdbi/result.rb

Overview

A result driver is a transformative element for RDBI::Result. Its design could be loosely described as a “fancy decorator”.

Usage and purpose is covered in the main RDBI::Result documentation. This section will largely serve the purpose of helping those who wish to implement result drivers themselves.

Creating a Result Driver

A result driver typically inherits from RDBI::Result::Driver and implements at least two methods: format_single_row and format_multiple_rows.

format_single_row is called with a single row fetched “raw” from the underlying driver, that is, with an array of variously typed elements. It is never called with a nil argument. format_multiple_rows is called with a possibly empty array of raw rows.

Note that format_multiple_rows could be implemented in terms of format_single_row. However, for performance reasons it is not.

Base class RDBI::Result::Driver additionally provides the method convert_row to employ RDBI’s type conversion facility (see RDBI::Type) for converting “raw” data elements to convenient ruby types. For performance reasons, RDBI converts on request instead of preemptively, so it is the driver implementor’s job to do any conversion.

Direct Known Subclasses

Array, CSV, Struct, YAML

Defined Under Namespace

Classes: Array, CSV, Struct, YAML

Instance Method Summary collapse

Constructor Details

#initialize(result, *args) ⇒ Driver

Result driver constructor. This is the logic that associates the result driver for decoration over the result; if you wish to override this method, please call super before performing your own operations.



343
344
345
# File 'lib/rdbi/result.rb', line 343

def initialize(result, *args)
  @result = result
end

Instance Method Details

#format_multiple_rows(raw_rows) ⇒ Object



351
352
353
# File 'lib/rdbi/result.rb', line 351

def format_multiple_rows(raw_rows)
  raw_rows.collect { |rr| convert_row(rr) }
end

#format_single_row(raw) ⇒ Object



347
348
349
# File 'lib/rdbi/result.rb', line 347

def format_single_row(raw)
  convert_row(raw)
end