Skip to content

Instantly share code, notes, and snippets.

@gevans
Created May 6, 2014 04:10
Show Gist options
  • Save gevans/d070ca040da979a2b03f to your computer and use it in GitHub Desktop.
Save gevans/d070ca040da979a2b03f to your computer and use it in GitHub Desktop.
Mongoid extension to support fields with type `HashWithIndifferentAccess`
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