Use published APIs for for decorates_association

This commit is contained in:
Michael Fairley 2011-12-06 11:25:26 -08:00
parent d10365551c
commit 7b6cd2634d
2 changed files with 8 additions and 11 deletions

View File

@ -60,12 +60,9 @@ module Draper
def self.decorates_association(association_symbol)
define_method(association_symbol) do
orig_association = model.send(association_symbol)
return nil if orig_association.nil?
if orig_association.respond_to? :proxy_reflection # The association is a collection
"#{orig_association.proxy_reflection.klass}Decorator".constantize.decorate(orig_association)
else
"#{orig_association.class}Decorator".constantize.decorate(orig_association)
end
return orig_association if orig_association.nil?
reflection = model.class.reflect_on_association(association_symbol)
"#{reflection.klass}Decorator".constantize.decorate(orig_association)
end
end

View File

@ -45,12 +45,12 @@ class Product < ActiveRecord::Base
yield
end
def self.reflect_on_association(association_symbol)
OpenStruct.new(:klass => self)
end
def similar_products
result = [Product.new, Product.new]
def result.proxy_reflection
OpenStruct.new(:klass => Product)
end
result
[Product.new, Product.new]
end
def previous_version