It is part of YaST where you can find more information about YaST and its component system. The Ruby bindings cover only the connection to the component system and provide some Ruby helpers.
It started as an experimental project to allow writting in Ruby, but after a decision to switch from an own language YCP to Ruby, it is a major part of YaST needed by almost all parts. As a relict from the language switch it contains constructs to keep backward compatibility which need a human decision before being removed.
Publish, Import and Include
The connection to the YaST component system has two parts.
The first one is the ability
to be called from the component system. Clients can be called via WFM (see below )
and modules provide an interface via the
publish method, where the type
signature is specified.
Publish is very similar to dbus interface provision. For more details see inline
documentation of . If a method is needed only from Ruby,
publish is not needed.
The second part is calling methods from the component system. Clients are called via WFM (see below). Methods from modules are imported with, which loads a component and creates a Ruby object in the Yast namespace from it, on which exported methods can be called. Note that if a call is done from Ruby to Ruby, then it is not limited by the component system and its protocol, so all Ruby features can be used.
# how to import a module and call it require "yast" Yast.import "IP" puts Yast::IP.Check4("127.0.0.333")
A relict from the transformation from YCP to Ruby is
the exception that an Include object can include other Include objects and thus there is
a special constructor instead of common Ruby
Ruby bindings provide a set of various helpers for working with the YaST component system or for making the translation from YCP to Ruby easier. Here is an overview of important provided classes with links to the inline documentation and a short explanation:
- : a class to be used for passing arguments by reference. Works even for Ruby immutable types like Fixnum or Symbol.
- : this module contains YCP builtins that need to be simulated in Ruby. For new code it should not be used.
- : a base class for clients in Ruby. It is not strictly required to inherit from it, but it adds useful helpers.
- : simulates type conversion. Not needed in new code.
: provides the method
- : a container used to pass references to methods to the component system.
- : provides methods used for translations.
- : a base class for YaST modules in Ruby. It is not strictly required to inherit from it, but it adds useful helpers.
- : this module contains YCP operators that need to be simulated in Ruby. For new code it should not be used.
- : represents the path type from the YCP protocol.
- : allows usage of SCR component for communication with the Linux system.
- : represents the term type from the YCP protocol. Often used for UI.
- : allows usage of WFM component. WFM is used for calling clients, and for setting a new SCR instance as the global one.
: a Ruby Logger configured to work with the YaST log with proper
place to use. The Ruby module provides easy access via the method
- : the namespace itself contains a few helpers to be used. It contains shortcuts and a method for a deep copy of an object.
provides shortcuts for UI terms. It is useful to construct dialogs or even popups.
# usage with Term content = Yast::Term.new( :ButtonBox, Yast::Term.new( :PushButton, Yast::Term.new(:id, :ok_button), "OK" ) Yast::Term.new( :PushButton, Yast::Term.new(:id, :cancel_button), "Cancel" ) ) # usage with shortcuts include Yast::UIShortcuts content = ButtonBox( PushButton(Id(:ok_button), "OK"), PushButton(Id(:cancel_button), "Cancel") )
The YaST team encourages to use RSpec for testing YaST code in Ruby. To help in that task, this gem includes some RSpec extensions under thenamespace. In order to use these extensions, the following line must be added to the tests.
For example, the following code makes use of the #path helper provided by.
require 'yast/rspec' describe ".proc.meminfo agent" do it "returns a Hash" do value = Yast::SCR.Read(path(".proc.meminfo")) expect(value).to be_a(Hash) end end
More information about YaST can be found on its homepage. More information about Ruby bindings can be found in the generated documentation.
How to Compile
Use the latest yast2-devtools, then use these calls:
mkdir build cd build cmake .. make
How to Install
Compile it, and from the
build directory call as root:
How to Create a Tarball
Then the RPM sources are in the
If Ruby code raises an exception, then the method returns
nil to YCP,
and the method
last_exception returns the message of the exception.
Also, exception details are logged.