Last active
December 16, 2015 01:59
-
-
Save gevans/5358794 to your computer and use it in GitHub Desktop.
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
# app/models/example.rb | |
class Example | |
include Mongoid::Document | |
field :data, type: Hashie::Mash | |
end |
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
require 'hashie' | |
module Mongoid | |
module Extensions | |
module Mash | |
module ClassMethods | |
def demongoize(object) | |
::Hashie::Mash.new(object) | |
end | |
def mongoize(object) | |
case object | |
when ::Hashie::Mash, ::Hash | |
object.mongoize | |
else | |
super | |
end | |
end | |
end # ClassMethods | |
end # Mash | |
end # Extensions | |
end # Mongoid | |
::Hashie::Mash.__send__(:include, Mongoid::Extensions::Mash) | |
::Hashie::Mash.__send__(:extend, Mongoid::Extensions::Mash::ClassMethods) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment