Class: RR::TypeCastingCursor
- Inherits:
-
Object
- Object
- RR::TypeCastingCursor
- Defined in:
- lib/rubyrep/type_casting_cursor.rb
Overview
Provides functionality to cast a query result value into the correct ruby type. Requires originating table and column to be known.
Instance Attribute Summary collapse
-
#columns ⇒ Object
A column_name => Column cache.
-
#org_cursor ⇒ ResultFetcher
The original cursor.
Instance Method Summary collapse
- #clear ⇒ Object
- #connection ⇒ Object
-
#initialize(connection, table, cursor) ⇒ TypeCastingCursor
constructor
Creates a new TypeCastingCursor based on provided database connection and table name for the provided database query cursor.
-
#next? ⇒ Boolean
Delegate the uninteresting methods to the original cursor.
-
#next_row ⇒ Object
Reads the next row from the original cursor and returns the row with the type casted row values.
- #options ⇒ Object
Constructor Details
#initialize(connection, table, cursor) ⇒ TypeCastingCursor
Creates a new TypeCastingCursor based on provided database connection and table name for the provided database query cursor
20 21 22 23 24 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 20 def initialize(connection, table, cursor) self.org_cursor = cursor self.columns = {} connection.columns(table).each {|c| columns[c.name] = c} end |
Instance Attribute Details
#columns ⇒ Object
A column_name => Column cache
16 17 18 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 16 def columns @columns end |
#org_cursor ⇒ ResultFetcher
Returns the original cursor.
13 14 15 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 13 def org_cursor @org_cursor end |
Instance Method Details
#clear ⇒ Object
8 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 8 def clear; org_cursor.clear end |
#connection ⇒ Object
9 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 9 def connection; org_cursor.connection end |
#next? ⇒ Boolean
Delegate the uninteresting methods to the original cursor
7 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 7 def next?; org_cursor.next? end |
#next_row ⇒ Object
Reads the next row from the original cursor and returns the row with the type casted row values.
27 28 29 30 31 32 33 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 27 def next_row row = org_cursor.next_row row.each do |column, value| row[column] = connection.connection.fixed_type_cast value, columns[column] end row end |
#options ⇒ Object
10 |
# File 'lib/rubyrep/type_casting_cursor.rb', line 10 def ; org_cursor. end |