Created
August 2, 2012 12:03
-
-
Save gcaixeta/3236545 to your computer and use it in GitHub Desktop.
define class methods to access denormalized fields at the _fields hash
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 AlizeExtension | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def alize_with_methods(relation, *fields) | |
alize relation, *fields | |
fields.each do |field| | |
define_method "#{relation}_#{field}" do | |
send("#{relation}_fields").try(:[], "#{field}") | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment