lib/draper/finders.rb in draper-1.0.0.beta6 vs lib/draper/finders.rb in draper-1.0.0
- old
+ new
@@ -1,6 +1,9 @@
module Draper
+ # Provides automatically-decorated finder methods for your decorators. You
+ # do not have to extend this module directly; it is extended by
+ # {Decorator.decorates_finders}.
module Finders
def find(id, options = {})
decorate(source_class.find(id), options)
end
@@ -15,20 +18,20 @@
def last(options = {})
decorate(source_class.last, options)
end
+ # Decorates dynamic finder methods (`find_all_by_` and friends).
def method_missing(method, *args, &block)
- result = super
+ return super unless method =~ /^find_(all_|last_|or_(initialize_|create_))?by_/
+
+ result = source_class.send(method, *args, &block)
options = args.extract_options!
- case method.to_s
- when /^find_((last_)?by_|or_(initialize|create)_by_)/
- decorate(result, options)
- when /^find_all_by_/
+ if method =~ /^find_all/
decorate_collection(result, options)
else
- result
+ decorate(result, options)
end
end
end
end