Skip to content

Instantly share code, notes, and snippets.

@jphenow
Last active December 17, 2015 13:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphenow/5614868 to your computer and use it in GitHub Desktop.
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
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