Class: Db2Query::Result
- Inherits:
-
ActiveRecord::Result
- Object
- ActiveRecord::Result
- Db2Query::Result
show all
- Defined in:
- lib/db2_query/result.rb
Defined Under Namespace
Classes: Record
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(columns, rows, definition) ⇒ Result
Returns a new instance of Result.
11
12
13
14
15
|
# File 'lib/db2_query/result.rb', line 11
def initialize(columns, rows, definition)
@definition = definition
validate_result_columns(columns)
super(columns, rows, {})
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/db2_query/result.rb', line 81
def method_missing(method_name, *args, &block)
if record.respond_to?(method_name)
record.send(method_name)
else
super
end
end
|
Instance Attribute Details
#definition ⇒ Object
Also known as:
query
Returns the value of attribute definition.
5
6
7
|
# File 'lib/db2_query/result.rb', line 5
def definition
@definition
end
|
Instance Method Details
#inspect ⇒ Object
37
38
39
40
41
|
# File 'lib/db2_query/result.rb', line 37
def inspect
entries = records.take(11).map!(&:inspect)
entries[10] = "..." if entries.size == 11
"#<#{self.class.name} [#{entries.join(', ')}]>"
end
|
#record ⇒ Object
17
18
19
|
# File 'lib/db2_query/result.rb', line 17
def record
records.first
end
|
#records ⇒ Object
21
22
23
|
# File 'lib/db2_query/result.rb', line 21
def records
@records ||= rows.map { |row| new_record(row) }
end
|
#to_h ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/db2_query/result.rb', line 25
def to_h
rows.map do |row|
index, hash = [0, {}]
while index < columns.length
attr_name = columns[index].to_sym
hash[attr_name] = data_type(attr_name).deserialize(row[index])
index += 1
end
hash
end
end
|