<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,11 +1,22 @@
-== Fetches ==
+= Fetches
 
 Fetches is a simple extension to ActionController that allows you to DRY up your
 model fetching with a simple, intuitive syntax. Rather than creating helpers or
 manually finding records each time an action is processed, simply add a call to
 'fetches' in your controller and it will take care of the rest.
 
-== Example ==
+== Installation
+
+Fetches is available as a gem as well as in traditional plugin format. To install
+as a gem, add this to your environment.rb:
+
+  config.gem 'mbleigh-fetches', :source =&gt; 'http://gems.github.com', :lib =&gt; &quot;fetches&quot;
+  
+To install it as a traditional plugin:
+
+  script/plugin install git://github.com/mbleigh/fetches.git
+
+== Example
 
   class UsersController &lt; ApplicationController
     fetches :user
@@ -26,6 +37,13 @@ It's very simple, and can also be extended to meet more complex demands, such as
       author # equivalent to User.find_by_login(params[:user_id])
     end
   end
+  
+You may also pass a Proc into the &quot;from&quot; option in order to fetch from
+a more complex set of requirements:
+
+  class UsersController &lt; ApplicationController
+    fetches :user, :from =&gt; Proc.new{ |c| c.params[:user_id] || c.params[:id] }
+  end
 
 The helper method generated memoizes (initializes once then doesn't make additional
 calls to the database) and is available both in the controller and the view.</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,10 @@ module ActionController
         @@default_fetcher_options = { :using =&gt; &quot;find&quot;,
                                       :from =&gt; :id }
         cattr_accessor :default_fetcher_options
+        
+        def self.fetchers
+          read_inheritable_attribute(:fetchers) || write_inheritable_attribute(:fetchers, {})
+        end
 
         # Automatically creates a helper method to fetch a memoized record based on
         # a passed-in parameter.
@@ -21,10 +25,16 @@ module ActionController
         #     fetches :article
         #   end
         #
+        #  # Example with Proc-based 'from'
+        #  class UsersController &lt; ApplicationController
+        #    fetches :user, :from =&gt; Proc.new{ |c| c.params[:user_id] || c.params[:id] }
+        #  end
+        #
         # Options:
         #
         # - +as+: the name of the helper method to generate (default is the model name)
-        # - +from+: the parameter passed into the finder method (default is +:id+)
+        # - +from+: the parameter passed into the finder method (default is +:id+). 
+        #     May also be passed as a +Proc+ that evaluates against a controller argument.
         # - +using+: the class method name to use as a finder (default is +&quot;find&quot;+)
         #
         # Default options may be specified by setting them in an initializer. Example:
@@ -34,15 +44,17 @@ module ActionController
           method_name = options.delete(:as) || default_fetcher_options[:as] || model_name.to_s
           finder = options.delete(:using) || default_fetcher_options[:using]
           from = options.delete(:from) || default_fetcher_options[:from]
-          
           klass = self.respond_to?(:class_eval) ? self : self.metaclass
+          fetchers[method_name.to_sym] = from
           
           klass.class_eval &lt;&lt;-EOS, __FILE__, __LINE__
             def #{method_name}
               if defined?(@#{method_name})
                 @#{method_name}
               else
-                @#{method_name} = #{model_name.to_s.classify}.#{finder.to_s}(params[#{from.inspect}])
+                fetcher = self.class.fetchers[:#{method_name}]
+                from = fetcher.is_a?(Proc) ? fetcher.call(self) : params[fetcher]
+                @#{method_name} = #{model_name.to_s.classify}.#{finder.to_s}(from)
               end
             end
           EOS</diff>
      <filename>lib/action_controller/fetches.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@ class FetchTestModel
     when 2
       &quot;two worked&quot;
     else
-      raise ActiveRecord::RecordNotFound, &quot;Couldn't find FetchTestModel with ID=#{some_integer.to_i}&quot;
+      raise &quot;Couldn't find FetchTestModel with ID=#{some_integer.to_i}&quot;
     end
   end
   </diff>
      <filename>test/fetcher_test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,6 +20,6 @@ class FetchesTest &lt; Test::Unit::TestCase
     controller.params = {:id =&gt; 2}
     assert_equal &quot;two worked&quot;, controller.fetch_test_model
     controller.params = {:id =&gt; 3}
-    assert_throws(ActiveRecord::RecordNotFound)
+    assert_throws(Exception)
   end
 end</diff>
      <filename>test/fetches_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>16db8ef3a7ef3a069e66204e2fe4306e14f717cd</id>
    </parent>
  </parents>
  <author>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </author>
  <url>http://github.com/mbleigh/fetches/commit/784e946928aea912fd9ff0537c544bbb43eff934</url>
  <id>784e946928aea912fd9ff0537c544bbb43eff934</id>
  <committed-date>2008-07-28T11:02:52-07:00</committed-date>
  <authored-date>2008-07-28T11:02:52-07:00</authored-date>
  <message>Allow Proc calls for the :from option.</message>
  <tree>f9ff4d3e2dcc0bef0ebc9322b696af818bec9fa1</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
