Created
May 6, 2014 04:10
-
-
Save gevans/d070ca040da979a2b03f to your computer and use it in GitHub Desktop.
Mongoid extension to support fields with type `HashWithIndifferentAccess`
This file contains hidden or 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 Extensions | |
module HashWithIndifferentAccess | |
def mongoize | |
::HashWithIndifferentAccess.mongoize(self) | |
end | |
module ClassMethods | |
def demongoize(object) | |
::Hash.demongoize(object).try(:with_indifferent_access) | |
end | |
def mongoize(object) | |
::Hash.mongoize(object) | |
end | |
end # ClassMethods | |
end # HashWithIndifferentAccess | |
end # Extensions | |
::HashWithIndifferentAccess.__send__(:include, Extensions::HashWithIndifferentAccess) | |
::HashWithIndifferentAccess.extend(Extensions::HashWithIndifferentAccess::ClassMethods) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment