draper/spec/performance/decorators.rb

46 lines
819 B
Ruby
Raw Permalink Normal View History

require "./performance/models"
2012-10-09 08:51:40 +00:00
class ProductDecorator < Draper::Decorator
2012-02-13 15:24:31 +00:00
def awesome_title
"Awesome Title"
end
2012-02-13 15:24:31 +00:00
# Original #method_missing
def method_missing(method, *args, &block)
if allow?(method)
begin
model.send(method, *args, &block)
rescue NoMethodError
super
end
else
super
end
end
end
2012-10-09 08:51:40 +00:00
class FastProductDecorator < Draper::Decorator
2012-02-13 15:24:31 +00:00
def awesome_title
"Awesome Title"
end
2012-02-13 15:24:31 +00:00
# Modified #method_missing
def method_missing(method, *args, &block)
if allow?(method)
begin
self.class.send :define_method, method do |*args, &block|
model.send(method, *args, &block)
end
self.send(method, *args, &block)
rescue NoMethodError
super
end
else
super
end
end
end