|
Post by jontara on Jun 5, 2017 4:11:50 GMT
I'm surprised I haven't run across this before... but you can easily run into technical Ruby naming conflicts when naming your Rhom models.
After never having encountered this before, I got TWO on the same project.
I had models named Class and Module. And chaos ensues!
I decided that Lesson is better than Module. And that Course might work for Class. (Notwithstanding differences between US and British usage of those words...)
I suppose the safe thing is to put some unique prefix or suffix on all of all of your model names. But, no matter how short, that will still make some ugly code.
Has anyone else encountered this? If so, how did you solve it? Is there some obvious solution I am missing? Is there some possible future fix that could be done in Rhodes?
Anyone have a clever solution that isn't ugly?
|
|
|
Post by Alex Epifanov on Jun 6, 2017 6:15:00 GMT
Never encountered this issue, honestly. Adding prefix or suffix may work - maybe just for models with conflicting names. Another way I see is not to allow adding of this kind of models to the app - make some checks if model name conflicts with Ruby keywords at build time or when running add model command.
|
|
|
Post by jontara on Jun 6, 2017 16:41:58 GMT
BTW, I also discovered some Rhodes restrictions on model names, most of which I was previously aware of. One though surprised me! It should be better documented. It appears a model directory must start with exactly one single capital letter. I made the unfortunate choice of calling a model HTMLContent. I had to change it to HtmlContent. It is I guess a side-effect of mixing models directories and other directories under "app". The first-letter capitalization appears to be how Rhodes knows that a directory contains a model. It would have been better to both put models under some directory of their own and as well to namespace them. They might be included automatically as well as they are now. So, if you had a problematic model name, you could always refer to e.g. Model::Module or Model::Class. I didn't want to use a prefix and make the code ugly. It is the Ruby way to favor pretty code over absolutely safe conventions. That's why you see 'klass' in lots of Ruby code. And why new Ruby programmers get tripped-up over this the first time they try to call something "class". I should have known better!
|
|