[yast-devel] simple ruby client to test SCR code?
Hi, what is the simplest Ruby based client to test SCR code? I tried something like this: module X include Yast r = SCR.Execute(path(".target.bash"), "/usr/bin/true") Builtins.y2milestone(r) end but here path is undefined. Regards, Arvin -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Mon, Sep 09, 2013 at 12:21:31PM +0200, Arvin Schnell wrote:
what is the simplest Ruby based client to test SCR code?
$ ruby -r yast -e 'Yast::SCR.Execute(Yast::Path.new(".target.bash"), "xeyes")'
I tried something like this:
module X include Yast r = SCR.Execute(path(".target.bash"), "/usr/bin/true") Builtins.y2milestone(r) end
but here path is undefined.
Ruby modules, besides being namespaces as you would expect, are designed to work as *mixins*. That is, a def in a module is by default available to *instances* of classes that include the module. Above, "path" is undefined because you call it in the X module, not in an object. Many modules are designed to work without instances, but they must explicitly declare their methods as such with http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_module.html#Module.m... or with "extend self" which is a cryptic way of doing so for all its methods. Attached is a working example similar to yours. -- Martin Vidner, Cloud & Systems Management Team http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
Dne 9.9.2013 12:21, Arvin Schnell napsal(a):
Hi,
what is the simplest Ruby based client to test SCR code?
I tried something like this:
module X include Yast r = SCR.Execute(path(".target.bash"), "/usr/bin/true") Builtins.y2milestone(r) end
but here path is undefined.
If you include the Yast module, the 'path' method will be added to the instance methods of the module X, which is a different scope from where you expect it in the code example above. This should work: module X include Yast def scr_execute SCR.Execute(path(".target.bash"), '/usr/bin/true') end end The 'path' method is a shortcut for Yast::Path.new(*args) [1]. If you want to use it in the module scope, you must specify the full namespace. [1] https://github.com/yast/yast-ruby-bindings/blob/master/src/ruby/yast/yast.rb vlado
Regards, Arvin
Dne 9.9.2013 12:45, Vladimir Moravec napsal(a):
Dne 9.9.2013 12:21, Arvin Schnell napsal(a):
Hi,
what is the simplest Ruby based client to test SCR code?
I tried something like this:
module X include Yast r = SCR.Execute(path(".target.bash"), "/usr/bin/true") Builtins.y2milestone(r) end
but here path is undefined.
If you include the Yast module, the 'path' method will be added to the instance methods of the module X, which is a different scope from where you expect it in the code example above.
This should work:
module X include Yast
def scr_execute SCR.Execute(path(".target.bash"), '/usr/bin/true') end end
The 'path' method is a shortcut for Yast::Path.new(*args) [1]. If you want to use it in the module scope, you must specify the full namespace.
I was a bit incorrect, sorry. As the 'include' statement puts the constants of the Yast module into the scope of module X, it's not required to use the 'Yast' namespace for accessing the 'Path': module X include Yast r = SCR.execute(Path.new('.target.bash'), '/usr/bin/true') end However, the SCR call will be executed only once during module X evaluation and because you assigned it to a local module variable it is practically useless - typically you would want it for a constant which makes is useful after you mix-in the module X into another class or module where you can make use of it. vlado
[1] https://github.com/yast/yast-ruby-bindings/blob/master/src/ruby/yast/yast.rb
vlado
Regards, Arvin
participants (3)
-
Arvin Schnell
-
Martin Vidner
-
Vladimir Moravec