We see these problems in this area:
- Polluting the Ruby top-level namespaces with names as generic as Installation, Packages or UI.
- Inconsistencies.
- Collisions (e.g. Storage is already a module and cannot be used as a namespace).
Let's see some examples:
::Registration::UI::Dialog
vs::UI::InstallationDialog
::Installation::FinishClient
vsYast::PkgFinishClient
You can see a complete example in PkgFinishClient.
- PkgFinishClient lives in Yast namespace (although is located in
lib/packages/clients/pkg_finish.rb
; more on that, later). - It inherits from
::Installation::FinishClient
, which live outside the YaST namespace (polluting the top-level one).
About source code layout, situation is not that bad but it can be improved. Sometimes is not straightforward to find where a class/module is defined (it's easy enough using grep or the Github search, but I'd prefer a more consistent/predictible way).
Although it's not mandatory, using a single class/module per file and naming the file as the class/module (but replacing CamelCase with snake_case) is the preferred option within the Ruby community.
Going back to PkgFinishClient
, it should live in
pkg_finish_client.rb
. And a Yast::SomeModule::Clients::SomeClient
class should be defined in
lib/yast/somemodule/clients/some_client.rb
.
Steffen pointed out that if he requires yast/storage
, he would
expect all storage code to be loaded. And he's right. If you want to
load only a class/file, you can require yast/storage/some_class
.
In an installed system, all YaST2 Ruby code lives in
/usr/share/YaST2
. That's fine for things like modules
(/usr/share/YaST2/modules
) which are quite YaST-specific. But from a
Ruby developer point of view, libraries should live in
/usr/lib64/ruby/vendor_ruby
(or something like that).
I'd prefer
some_client_test.rb
(orsome_client_spec.rb
) test file name. It makes searching (find
) for clients in the sources (esp. in all YaST repositories) easier as you do not have to filter out the/test/
paths.