cbrain icon indicating copy to clipboard operation
cbrain copied to clipboard

Some read-only DPs return false for "read_only?"

Open prioux opened this issue 1 year ago • 1 comments

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.

  1. make sure the DB column is also consistent; maybe with a general callback in after_update() ?
  2. override read_only? too
  3. ...
  4. profit!
  5. my slashdot ID is 5 digits long

prioux avatar Jun 18 '24 16:06 prioux

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

MontrealSergiy avatar Jul 08 '24 19:07 MontrealSergiy

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.

MontrealSergiy avatar Jul 17 '24 20:07 MontrealSergiy

@prioux Should I work on it, or would you prefer to take care of it yourselves?

MontrealSergiy avatar Sep 09 '24 15:09 MontrealSergiy

Fixed all the DPs with an explicit

def read_only?
   true
end

prioux avatar Sep 09 '24 20:09 prioux

https://github.com/aces/cbrain/commit/fab9c9193e176e42f4d8f7f7d41088d3f2cf7a00 and https://github.com/aces/cbrain-plugins-neuro/commit/f8f656d27f486ffe67a031fc040b0998a6908663

prioux avatar Sep 09 '24 20:09 prioux