Sha256: 920a1c2ada2fd7cc1a89846f420449cb37b4db766fec1357035f5aa959ec2ab0
Contents?: true
Size: 928 Bytes
Versions: 36
Compression:
Stored size: 928 Bytes
Contents
module ActiveRecord ### # This class encapsulates a Result returned from calling +exec_query+ on any # database connection adapter. For example: # # x = ActiveRecord::Base.connection.exec_query('SELECT * FROM foo') # x # => #<ActiveRecord::Result:0xdeadbeef> class Result include Enumerable attr_reader :columns, :rows def initialize(columns, rows) @columns = columns @rows = rows @hash_rows = nil end def each hash_rows.each { |row| yield row } end def to_hash hash_rows end private def hash_rows @hash_rows ||= begin # We freeze the strings to prevent them getting duped when # used as keys in ActiveRecord::Model's @attributes hash columns = @columns.map { |c| c.dup.freeze } @rows.map { |row| Hash[columns.zip(row)] } end end end end
Version data entries
36 entries across 31 versions & 6 rubygems