lib/frenchy/collection.rb in frenchy-0.0.7 vs lib/frenchy/collection.rb in frenchy-0.0.8
- old
+ new
@@ -1,10 +1,20 @@
module Frenchy
class Collection < ::Array
# Decorate the collection using the name of the decorator inferred by the first record
- def decorate
- decorator_class = "#{first.class.name}Decorator".constantize
- decorator_class.decorate(self)
+ def decorate(options={})
+ return self if none?
+
+ if decorator_class.respond_to?(:decorate_collection)
+ decorator_class.decorate_collection(self)
+ else
+ decorator_class.decorate(self)
+ end
+ end
+
+ # Compatbility for associations in draper
+ def decorator_class
+ "#{first.class.name}Decorator".constantize
end
# Backwards compatibility for old version of draper
def nil?
none?