Skip to content

Commit

Permalink
Initial commit of code
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Nov 2, 2010
0 parents commit f075db2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Empty file added README.md
Empty file.
7 changes: 7 additions & 0 deletions init.rb
@@ -0,0 +1,7 @@
require 'active_record_ext'
require 'array_ext'

# extend activerecord with the :preload method
ActiveRecord::Base.send(:extend, AssociationsPreload::Base)
# add :preload method to array
Array.send(:include, AssociationsPreload::Array)
9 changes: 9 additions & 0 deletions lib/active_record_ext.rb
@@ -0,0 +1,9 @@
module AssociationsPreload
module Base
def preload(records, *args)
include_associations = send(:merge_includes, send(:scope, :find, :include), args)
preload_associations(records, include_associations) unless include_associations.empty?
records
end
end
end
8 changes: 8 additions & 0 deletions lib/array_ext.rb
@@ -0,0 +1,8 @@
module AssociationsPreload
module Array
def preload(*args)
return self if self.empty?
first.class.preload(self, *args)
end
end
end

0 comments on commit f075db2

Please sign in to comment.