aces / cbrain

CBRAIN is a flexible Ruby on Rails framework for accessing and processing of large data on high-performance computing infrastructures.
GNU General Public License v3.0
70 stars 43 forks source link

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

Open prioux opened 1 month ago

prioux commented 1 month ago

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

MontrealSergiy commented 2 weeks ago

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 commented 1 week ago

Actually not only boolean, any attribute has 'truthiness/presentishness' check method, which differs only in question mark, something like name?, type?, 'description?' etc ... Note integer 0 considered by falthy falue.