Skip to content

Instantly share code, notes, and snippets.

@brianhempel
Created January 21, 2011 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianhempel/790161 to your computer and use it in GitHub Desktop.
Save brianhempel/790161 to your computer and use it in GitHub Desktop.
mongomapper custom types
class GlobalStats
include MongoMapper::Document
key :attempts, Attempts
end
class Attempts
attr_accessor :total, :hours
def self.to_mongo(attempts)
{
"total" => total,
"hours" => hours
}
end
def self.from_mongo(hash)
a = Attempts.new
a.total = hash["total"]
a.hours = hash["hours"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment