mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
48 lines
859 B
Ruby
48 lines
859 B
Ruby
|
require "./performance/models"
|
||
|
class ProductDecorator < Draper::Base
|
||
|
decorates :product
|
||
|
|
||
|
def awesome_title
|
||
|
"Awesome Title"
|
||
|
end
|
||
|
|
||
|
# 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
|
||
|
|
||
|
class FastProductDecorator < Draper::Base
|
||
|
decorates :product
|
||
|
|
||
|
def awesome_title
|
||
|
"Awesome Title"
|
||
|
end
|
||
|
|
||
|
# 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
|