Class: DB::Records

Inherits:
Object
  • Object
show all
Defined in:
lib/db/records.rb

Overview

A buffer of records.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, rows) ⇒ Records

Returns a new instance of Records.



18
19
20
21
# File 'lib/db/records.rb', line 18

def initialize(columns, rows)
	@columns = columns
	@rows = rows
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



32
33
34
# File 'lib/db/records.rb', line 32

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



33
34
35
# File 'lib/db/records.rb', line 33

def rows
  @rows
end

Class Method Details

.wrap(result) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/db/records.rb', line 9

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

#freezeObject



23
24
25
26
27
28
29
30
# File 'lib/db/records.rb', line 23

def freeze
	return self if frozen?
	
	@columns.freeze
	@rows.freeze
	
	super
end

#to_aObject



35
36
37
# File 'lib/db/records.rb', line 35

def to_a
	@rows
end