Skip to content

Instantly share code, notes, and snippets.

@gevans
Last active December 16, 2015 01:59
Show Gist options
  • Save gevans/5358794 to your computer and use it in GitHub Desktop.
Save gevans/5358794 to your computer and use it in GitHub Desktop.
# app/models/example.rb
class Example
include Mongoid::Document
field :data, type: Hashie::Mash
end
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