Mailinglist Archive: yast-devel (144 mails)

< Previous Next >
Re: [yast-devel] Help: Lost in Ruby
On Fri, Aug 09, 2013 at 05:35:44PM +0200, Arvin Schnell wrote:
On Fri, Aug 09, 2013 at 04:58:22PM +0200, David Majda wrote:
I didn't examine your patch in detail, but it seems to me that you are
mixing Ruby concepts (classes, modules) with ones inherited from YaST
(mainly includes). My general recommendations are the following:

* If you create a new class, put it into a separate file, don't make
it inherit from anything in Yast:: and don't make it part of any
YaST client, module or include. That will ensure separation of
concepts. One class per file is also usual convention in Ruby world.

Where should the new file be placed and how do I "include" it?
Remember, I'm new to Ruby.

Put it under lib, src/lib/partitioning/ep-all.rb
require "partitioning/ep-all"
see also

* If you need to use a YaST module in your class, then just import it
and use it -- that should work well.

With Yast.import, right?


* If you need to use a YaST include in the class, include it via Ruby
include as a Ruby module and call its initialize_* method (if any)
manually in the constructor.

You correctly note that this is ugly. The better way is probably to
extract the include functionality you need into a separate Ruby
class/module, use it in your class, and just delegate to the
extracted part in the include.

That sound like it involves moving lots of code, more or less all
ep-*.rb files. And even then all calls to the extracted functions
must be changed to include a namespace, e.g. from doit() to

Fair point. Prefixing calls with namespaces is a pain. We need to
look at the concrete example to find out how to avoid it.

Since all mistakes only show up at runtime that's hopeless.

This is a general problem which has a standard answer: automated
tests. Ruby should be greatly superior to YCP with respect to
testing tools, let's put it to practice. (yeah, easy to say)

* If you need to use any part of Ruby bindings (e.g. UI shortcuts) in
your class, just include the appropriate module. This may lead to
some duplication if you do it in many classes, which we will
probably need to address soon (in order to prevent everybody doing
his own thing).

I would do so in a dozen of classes.

Thanks for the help, but I think for the near future I have to
put my ideas on ice.

Step by step, we will get there.
Martin Vidner, Cloud & Systems Management Team

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
< Previous Next >