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.12 lib/active_record/result.rb
activerecord-3.1.11 lib/active_record/result.rb
activerecord-3.1.10 lib/active_record/result.rb
activerecord-3.1.9 lib/active_record/result.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
activerecord-3.1.8 lib/active_record/result.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
activerecord-3.1.7 lib/active_record/result.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb
activerecord-3.1.6 lib/active_record/result.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/result.rb