Created
October 12, 2013 01:10
-
-
Save tensiondriven/6944426 to your computer and use it in GitHub Desktop.
Store a model in a Mongoid field using YAML
This file contains 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
class YamlType | |
def mongoize | |
YAML.dump(object) | |
end | |
class << self | |
def mongoize(object) | |
YAML.dump(object) | |
end | |
def demongoize(object) | |
YAML.load(object) | |
end | |
def evolve(object) | |
case object | |
when String, Regex | |
object | |
else | |
object.mongoize | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment