Skip to content

Instantly share code, notes, and snippets.

@gcaixeta
Created August 2, 2012 12:03
Show Gist options
  • Save gcaixeta/3236545 to your computer and use it in GitHub Desktop.
Save gcaixeta/3236545 to your computer and use it in GitHub Desktop.
define class methods to access denormalized fields at the _fields hash
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