title: Implementing "after_find" in datamapper
body: <p>I've taken over porting a large application from rails 2 to rails 3. The new application uses Datamapper as its ORM (decision taken prior to me coming to the project, so I can't change this). </p>
  
  <p>The old application used the activerecord "after_find" callback quite extensively;</p>
  
  <pre><code>class Foo &lt; ActiveRecord::Base
    after_find :bar
    def bar
      #This would be called after an object was "found"
    end
  end
  </code></pre>
  
  <p>I need to implement this in Datamapper, but I can't just monkey patch the find methods because datamapper uses composition rather than inheritence;</p>
  
  <pre><code>class Foo
    include Datamapper::Resource
  end
  </code></pre>
  
  <p>so if I monkey patched the find methods, there would be no way of me calling the original method! Could anyone point me in the right direction?</p>
  
  <p>== EDIT ==</p>
  
  <p>I have tried including the following:</p>
  
  <pre><code>module ClassMethods
  
    def after_find(meth)
      class &lt;&lt; self
        alias_method :orig_first, :first
        def first(*args, &amp;block)
          puts "XXX FOUND THE FIRST"
          orig_first args, &amp;block
        end
      end
    end
  end
  </code></pre>
  
  <p>But this just sends the code into an infinite loop (constantly printing "XXX FOUND THE FIRST")</p>