Last active
December 17, 2015 13:09
-
-
Save jphenow/5614868 to your computer and use it in GitHub Desktop.
Get the attributes of a mongoid object with their aliased names as the keys
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 Game | |
include Mongoid::Document | |
def aliased_attributes | |
attributes.inject({}) { |attrs, (raw_key, raw_value)| | |
attrs[Game.aliased_fields.invert.fetch(raw_key) { raw_key }] = raw_value | |
attrs | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment