markevans/dragonfly — pull request #182 by eric1234 (2012-04-06 21:16:25+00:00)
Title: Fix for define_macro_on_include

I am attempting to use dragonfly with MongoMapper. Following the Mongoid playbook since they are similar. My initializer is:

require 'dragonfly/rails/images'

app = Dragonfly[:images]

app.datastore = Dragonfly::DataStorage::MongoDataStore.new

app.define_macro_on_include MongoMapper::Document, :image_accessor
app.define_macro_on_include MongoMapper::Document, :file_accessor
app.define_macro_on_include MongoMapper::EmbeddedDocument, :image_accessor
app.define_macro_on_include MongoMapper::EmbeddedDocument, :file_accessor

I am defining both the "image_accessor" and "file_accessor" like the default AR implementation because I think it makes the model code clearer. But when I tried to load my model I got a stack overflow error.

Seems to be caused by the alias method chain which is being defined the same for both calls to define_macro_on_include. This patch adjusts the naming to include the macro name as well which has removed the error for me.