Sha256: 29421daee7682505d74510c14627241bd2872555eed63b7c7668f42602be1263

Contents?: true

Size: 696 Bytes

Versions: 55

Compression:

Stored size: 696 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 ||= @rows.map { |row|
        Hash[@columns.zip(row)]
      }
    end
  end
end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
activerecord-3.1.5 lib/active_record/result.rb
activerecord-3.1.5.rc1 lib/active_record/result.rb
dirty_history-0.5.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
activerecord-3.1.4 lib/active_record/result.rb
activerecord-3.1.4.rc1 lib/active_record/result.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.10 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.9 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.8 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.7 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.6 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.5 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.4 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.4.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
activerecord-3.1.3 lib/active_record/result.rb
activerecord-3.1.2 lib/active_record/result.rb
activerecord-3.1.2.rc2 lib/active_record/result.rb