Hi all,
I am trying to write a more or less clean datamapper property for a
project we use inhouse. I was looking for documentation on this, but
didn't find much.
I am especially confused by this bit of code found in property.rb
(https://github.com/datamapper/dm-core/blob/master/lib/dm-core/property.rb#L699-707)
- implementation for valid?:
def valid?(value, negated = false)
dumped_value = dump(value)
if required? && dumped_value.nil?
negated || false
else
primitive?(dumped_value) || (dumped_value.nil? && (allow_nil?
|| negated))
end
end
When you assume:
- loaded values must be primitive or are typecast otherwise (to primitive)
- dumped values must be database compatible
then I would infer that you can check validity in two ways:
a) check if the loaded values are primitive
b) check if the dumped values can be stored in the database
But the above code checks if the dumped values are primitive?!?! Where
am I wrong? And what methods to override minimally to get:
- getters to return kind_of? class X
- setters to store kind_of? class X
- database store to store value.to_s
- database load to restore kind_of? class X
?
I have a workaround, but would really like to do this right and perhaps
contribute some documentation. After I understand the system, that is ;)
best regards,
kaspar
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.