Class: DB::Records
- Inherits:
-
Object
- Object
- DB::Records
- Defined in:
- lib/db/records.rb
Overview
A buffer of records.
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
-
.wrap(result) ⇒ Object
Wrap a database result into a Records instance.
Instance Method Summary collapse
-
#freeze ⇒ Object
Freeze the Records instance and its internal data structures.
-
#initialize(columns, rows) ⇒ Records
constructor
Initialize a new Records instance with columns and rows.
-
#to_a ⇒ Object
Get the rows as an array.
Constructor Details
#initialize(columns, rows) ⇒ Records
Initialize a new Records instance with columns and rows.
24 25 26 27 |
# File 'lib/db/records.rb', line 24 def initialize(columns, rows) @columns = columns @rows = rows end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
40 41 42 |
# File 'lib/db/records.rb', line 40 def columns @columns end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
41 42 43 |
# File 'lib/db/records.rb', line 41 def rows @rows end |
Class Method Details
.wrap(result) ⇒ Object
Wrap a database result into a Records instance.
12 13 14 15 16 17 18 19 |
# File 'lib/db/records.rb', line 12 def self.wrap(result) # We want to avoid extra memory allocations when there are no columns: if result.field_count == 0 return nil end return self.new(result.field_names, result.to_a) end |
Instance Method Details
#freeze ⇒ Object
Freeze the Records instance and its internal data structures.
31 32 33 34 35 36 37 38 |
# File 'lib/db/records.rb', line 31 def freeze return self if frozen? @columns.freeze @rows.freeze super end |
#to_a ⇒ Object
Get the rows as an array.
45 46 47 |
# File 'lib/db/records.rb', line 45 def to_a @rows end |