Skip to content

Instantly share code, notes, and snippets.

@mrmemes-eth
Created June 1, 2012 19:17
Show Gist options
  • Save mrmemes-eth/2854510 to your computer and use it in GitHub Desktop.
Save mrmemes-eth/2854510 to your computer and use it in GitHub Desktop.
Simple monkey patch for decent_exposure's nu_nu branch to add automatic decoration of singular resources. Throw this in config/initializers and monkey patch your way to victory! Assumes a module like the one included.
class DecentExposure::ActiveRecord::Finder
def decorated_singular_resource
singular_resource.extend("#{singular_resource.class.name}Decorator".constantize)
rescue NameError
singular_resource
end
def resource
if plural?
collection_resource
else
decorated_singular_resource
end
end
end
module UserDecorator
def full_name
[first_name, last_name].join(' ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment