Created
February 14, 2012 00:43
-
-
Save fgrehm/1821958 to your computer and use it in GitHub Desktop.
DM #attributes
This file contains hidden or 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
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