rails/rails — pull request #3871 by ernie (2011-12-06 01:23:07+00:00)
Title: Add value_of/values_of to AR::Base/AR::Relation

This patch basically amounts to a merge of Valium into Rails core. Implements value_of/values_of functionality as exists in https://github.com/ernie/valium.

Superset of the recent pluck functionality, with the following enhancements:

* Only runs the DB query if required. If the records have already been loaded, simply maps through them and reads the attributes
* Supports multiple attributes:

```ruby
User.where(:active => true).values_of(:name, :email).each do do |name, email|
puts "#{name}'s e-mail address is #{email}"
end
````
* deserializes serialized attributes

Added a few new tests, corrected test names. All tests pass, and all Valium specs pass without loading the Valium gem when this code is active, so this should be backwards-compatible for those people who are already using Valium.

Thanks!