我刚开始使用 DataMapper,发现自己经常做这种事情:
class MyModel
include DataMapper::Resource
property :id, Serial
property :serialized_credentials, String
def credentials
@credentials ||= YAML.load(self.serialized_credentials)
end
def credentials=(c)
@credentials = nil
self.serialized_credentials = YAML.dump(c)
end
end
这允许我为凭据传递一个哈希(例如)。
但是 DataMapper 是否已经为此提供了一种机制?