aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-28 18:06:01 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-28 18:06:01 +0100
commitfc276e5635821e65c04b8961170cc6bd3c11b923 (patch)
tree9bd4ed018858611248e9b6aa7392dced92bc814a /activerecord/lib/active_record/result.rb
parent8e53e058acea471eab7a1609dc150aa9fdbfa833 (diff)
parent6a3d6b7f1352efd3e7b931533740252b04850e27 (diff)
downloadrails-fc276e5635821e65c04b8961170cc6bd3c11b923.tar.gz
rails-fc276e5635821e65c04b8961170cc6bd3c11b923.tar.bz2
rails-fc276e5635821e65c04b8961170cc6bd3c11b923.zip
Merge branch 'master' into nested_has_many_through
Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/test/schema/schema.rb
Diffstat (limited to 'activerecord/lib/active_record/result.rb')
-rw-r--r--activerecord/lib/active_record/result.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
new file mode 100644
index 0000000000..8deff1478f
--- /dev/null
+++ b/activerecord/lib/active_record/result.rb
@@ -0,0 +1,30 @@
+module ActiveRecord
+ ###
+ # This class encapsulates a Result returned from calling +exec+ on any
+ # database connection adapter. For example:
+ #
+ # x = ActiveRecord::Base.connection.exec('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
+
+ private
+ def hash_rows
+ @hash_rows ||= @rows.map { |row|
+ ActiveSupport::OrderedHash[@columns.zip(row)]
+ }
+ end
+ end
+end