Skip to content

Instantly share code, notes, and snippets.

@EdgarOrtegaRamirez
Forked from firedev/decorated.rb
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgarOrtegaRamirez/1e57a4ecc1ca27a1ced6 to your computer and use it in GitHub Desktop.
Save EdgarOrtegaRamirez/1e57a4ecc1ca27a1ced6 to your computer and use it in GitHub Desktop.
# 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