Skip to content

Instantly share code, notes, and snippets.

@firedev
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save firedev/7a82059b30a2157d4c56 to your computer and use it in GitHub Desktop.
Save firedev/7a82059b30a2157d4c56 to your computer and use it in GitHub Desktop.
Hides Draper decorator inside the model and lazily decorates resources
# 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