Last active
August 29, 2015 14:04
-
-
Save firedev/7a82059b30a2157d4c56 to your computer and use it in GitHub Desktop.
Hides Draper decorator inside the model and lazily decorates resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hides Draper decorator inside the model and lazily decorates resources | |
# | |
# https://gist.github.com/firedev/7a82059b30a2157d4c56 | |
# | |
# model.rb: | |
# include Decorated | |
# | |
# Just make sure there are no overlapping method names in ModelDecorator | |
module Decorated | |
extend ActiveSupport::Concern | |
def method_missing(method, *args) | |
return decorated_resource.send(method, *args) if decorated_resource.respond_to?(method) | |
super | |
end | |
def decorated_resource | |
@decorated_resource ||= decorate | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment