Skip to content

Instantly share code, notes, and snippets.

@antw
Created January 12, 2010 21:37
Show Gist options
  • Save antw/275638 to your computer and use it in GitHub Desktop.
Save antw/275638 to your computer and use it in GitHub Desktop.
module DataMapper
module Mongo
module Model
# ...
# Defines a Property on the Resource
#
# Overrides the property method in dm-core so as to automatically map
# Array and Hash types to EmbeddedArray and EmbeddedHash respectively.
#
# @param [Symbol] name
# the name for which to call this property
# @param [Type] type
# the type to define this property ass
# @param [Hash(Symbol => String)] options
# a hash of available options
#
# @return [Property]
# the created Property
#
# @api public
def property(name, type, options = {})
if Array == type
type = DataMapper::Mongo::Types::EmbeddedArray
elsif Hash == type
type = DataMapper::Mongo::Types::EmbeddedHash
end
super(name, type, options)
end
end # Model
end # Mongo
end # DataMapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment