Skip to content

Instantly share code, notes, and snippets.

@fgrehm
Created February 14, 2012 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgrehm/1821958 to your computer and use it in GitHub Desktop.
Save fgrehm/1821958 to your computer and use it in GitHub Desktop.
DM #attributes
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite::memory:')
class Product
include DataMapper::Resource
property :id, Serial
property :category, String
property :subcategory, String
def categories
[self.category, self.subcategory]
end
def categories=(categories)
self.category = categories.first
self.subcategory = categories.last
end
end
Product.auto_upgrade!
product = Product.new(:categories => ['Foo', 'Bar'])
# Outputs only resource defined properties
p product.attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment