Created
June 1, 2012 19:17
-
-
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.
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
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 |
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
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