I have a scenario where I just need to inherite the classes in my subclass, there is not single line of code. Just due to STI I need to create it.
Ex:
|-- app
| |-- models
| | |-- a
| | | |-- a1
| | | | |-- special
| | | | | |-- a2
| | | | | | *-- ax1.rb #(A::A1::Special::A2::Ax1 < A::A1::A2::Ax)
| | | | |-- a2
| | | | | *-- ax.rb
| | |-- b
| | | |-- b1
| | | | |-- b2
| | | | | *-- bx.rb #(B::B1::B2::Bx)
| | |-- c
| | `-- concerns
Question and scenario:
I have lots of files like Ax1 which needs hierarchy but that doesn't contains anything except inheritance. So one way is to create all (unnecessary :( ) folders and put the file inside it as per Rails conventions.
And as I have many files so I want it to put in single file with all classes with inheritance (but as per Rails conventions, single class should be in single file with same name).
Is there any way to achieve this?
You can't do this without breaking "convention over configuration". But if you're willing to violate that, it's quite easy. Just put all your classes in one file, say,
app/models/my_classes.rband then just make sure that the file is loaded before you need any class from it.One way of doing this is create an initializer