Some read-only DPs return false for "read_only?"
Some DPs are meant to be read-only. Usually, they inform the rest of the system by just overriding the method read_only() in this way:
def read_only
true
end
The attribute read_only is a database column. However, for boolean columns, Rails also provide read_only? . Since that method is not overridden, it returns false if the DB's value has not been set. So we get this kind of behavior:
irb> d.read_only
=> true
irb> d.read_only?
=> false
There are several solutions. Not sure what is best.
- make sure the DB column is also consistent; maybe with a general callback in after_update() ?
- override
read_only?too - ...
- profit!
- my slashdot ID is 5 digits long
Well, I would go for variant 2 because it is probably enough to override read_only? method in the parent class and it affects the method immediately on creation. Also, optionally, variant 1 can be implemented in the same time, just to make database more consistent
Actually not only boolean, any attribute has #{attribute}? 'truthiness/presentishness' check method, which differs only in question mark, something like name?, type?, description? etc ... Note integer 0 considered as falthy value.
@prioux Should I work on it, or would you prefer to take care of it yourselves?
Fixed all the DPs with an explicit
def read_only?
true
end
https://github.com/aces/cbrain/commit/fab9c9193e176e42f4d8f7f7d41088d3f2cf7a00 and https://github.com/aces/cbrain-plugins-neuro/commit/f8f656d27f486ffe67a031fc040b0998a6908663