public
Description: Implements ActiveRecord::Base.each instance method
Homepage: http://github.com/guillermo/active_record_each/wikis
Clone URL: git://github.com/guillermo/active_record_each.git
guillermo (author)
Mon Jul 07 07:13:45 -0700 2008
commit  fd9e7f13af3444caa69872248c2fc00cde507a46
tree    14dc464895726a9c1c5e5c2f18c5cfc62ee7272e
parent  74c4b7ee6f51945d86741046323dbc68d87758bc
100644 35 lines (21 sloc) 1.048 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
=ActiveRecordEach
 
==Context
 
If you have to do a migration with a lot of rows, you can't do something like these
  User.find(:all).each do { |u| ... }
because you load all the table in ruby memmory. Ruby-prof says that these is not good, so I do these.
 
==Summary & Examples
 
ActiveRecordEach is a 5 minutes plugin that implements ActiveRecord::Base.each instance method.
 
It acepts any parameter that find accept except :limit
 
Now you can easily do
  User.each (:conditions => "users.login LIKE 'g%') { |u| Notifier.deliver_report(u) }
 
==Todo
It could be interesting make somthing like these:
  User.each (:step => 5) {|u| puts u.login}
 
And fetch 5 users per query
 
==Installation
 
You have two methods:
 * If your rails app is managed by git
  git-submodule add git://github.com/guillermo/active_record_each.git vendor/plugins/active_record_each
 
 * If doesn't
  git-clone git://github.com/guillermo/active_record_each.git vendor/plugins/active_record_each
 
 
Copyright (c) 2008 Guillermo Álvarez Fernández, released under the MIT license