Module: Yast
- Defined in:
- src/binary/Yast.cc,
src/ruby/yast/ops.rb,
src/ruby/yast/scr.rb,
src/ruby/yast/wfm.rb,
src/ruby/yast/i18n.rb,
src/ruby/yast/path.rb,
src/ruby/yast/term.rb,
src/ruby/yast/yast.rb,
src/ruby/yast/break.rb,
src/ruby/yast/client.rb,
src/ruby/yast/logger.rb,
src/ruby/yast/module.rb,
src/ruby/yast/arg_ref.rb,
src/ruby/yast/convert.rb,
src/ruby/yast/fun_ref.rb,
src/ruby/yast/builtins.rb,
src/ruby/yast/debugger.rb,
src/ruby/yast/external.rb,
src/ruby/yast/y2logger.rb,
src/ruby/yast/rspec/scr.rb,
src/ruby/yast/exportable.rb,
src/ruby/yast/translation.rb,
src/ruby/yast/ui_shortcuts.rb,
src/ruby/yast/rspec/helpers.rb,
src/ruby/yast/rspec/matchers.rb,
src/ruby/yast/rspec/shortcuts.rb,
src/ruby/yast/y2start_helpers.rb,
src/ruby/yast/core_ext/ansi_string.rb
Overview
The YaST module encloses all Yast related code.
Defined Under Namespace
Modules: Builtins, Convert, CoreExt, Exportable, I18n, Logger, Ops, RSpec, SCR, Translation, UIShortcuts, WFM, Y2StartHelpers Classes: AbortException, ArgRef, Break, Byteblock, Client, Debugger, External, FunRef, LogGroupResult, Module, Path, Term, Y2Logger, YReference
Class Method Summary collapse
-
.arg_ref(*args) ⇒ Object
shortcut to construct new argument reference.
-
.deep_copy(object, options = {}) ⇒ Object
Makes deep copy of object.
-
.fun_ref(*args) ⇒ Object
shortcut to construct new function reference.
-
.import(mname) ⇒ Object
imports component module with given name and create wrapper for it.
-
.include(target, path) ⇒ Object
deprecated
Deprecated.
use "lib" directory where you can place common ruby code without any special handling.
-
.path(value) ⇒ Object
shortcut to construct new Yast path.
-
.term(*args) ⇒ Object
shortcut to construct new Yast term.
-
.y2debug(*args) ⇒ Object
write to log debug message with arguments formated by Builtins.sformat.
-
.y2error(*args) ⇒ Object
write to log error message with arguments formated by Builtins.sformat.
-
.y2internal(*args) ⇒ Object
write to log internal error message with arguments formated by Builtins.sformat.
-
.y2milestone(*args) ⇒ Object
write to log milestone message with arguments formated by Builtins.sformat.
-
.y2security(*args) ⇒ Object
write to log security message with arguments formated by Builtins.sformat.
-
.y2warning(*args) ⇒ Object
write to log warning message with arguments formated by Builtins.sformat.
Instance Method Summary collapse
-
#deep_copy(object) ⇒ Object
(also: #copy_arg)
Shortcut for Yast::deep_copy.
Class Method Details
.arg_ref(*args) ⇒ Object
shortcut to construct new argument reference
35 36 37 |
# File 'src/ruby/yast/yast.rb', line 35 module_function def arg_ref(*args) ArgRef.new(*args) end |
.deep_copy(object, options = {}) ⇒ Object
String, Yast::Path and Yast::Byteblock is also immutable in sense of Yast because there is no builtin operation for string modify that do not copy it. Use :full option to copy it also.
Makes deep copy of object. Difference to #dup or #clone is that it copy all elements of Array, Hash, Yast::Term. Immutable classes is just returned.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'src/ruby/yast/yast.rb', line 78 def self.deep_copy(object, = {}) case object when Numeric, TrueClass, FalseClass, NilClass, Symbol # immutable object when ::String, Yast::Path, Yast::Byteblock # immutable in sense of yast buildins [:full] ? object.clone : object when Yast::FunRef, Yast::ArgRef, Yast::External, Yast::YReference, Yast::YCode # contains only reference somewhere object when ::Hash object.each_with_object({}) do |kv, acc| acc[deep_copy(kv[0])] = deep_copy(kv[1]) end when ::Array object.each_with_object([]) do |v, acc| acc << deep_copy(v) end else object.clone # deep copy end end |
.fun_ref(*args) ⇒ Object
shortcut to construct new function reference
29 30 31 |
# File 'src/ruby/yast/yast.rb', line 29 module_function def fun_ref(*args) FunRef.new(*args) end |
.import(mname) ⇒ Object
for components written in ruby just require it and it is used directly without component system.
imports component module with given name and create wrapper for it.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'src/ruby/yast/yast.rb', line 165 def self.import(mname) modules = mname.split("::") base = Yast # Handle multilevel modules like YaPI::Network modules[0..-2].each do |module_| tmp_m = if base.constants.include?(module_.to_sym) base.const_get(module_) else base.const_set(module_, ::Module.new) end base = tmp_m end # do not reimport if already imported and contain some methods # ( in case namespace contain some methods ) if base.constants.include?(modules.last.to_sym) && !base.const_get(modules.last).public_methods(false).empty? return end import_pure(mname) # do not create wrapper if module is in ruby and define itself object if base.constants.include?(modules.last.to_sym) && !base.const_get(modules.last).public_methods(false).empty? return end m = if base.constants.include?(modules.last.to_sym) base.const_get(modules.last) else ::Module.new end symbols(mname).each do |sname, stype| next if sname.empty? if stype == :function m.define_singleton_method(sname) do |*args| caller(1,1).first.match BACKTRACE_REGEXP next Yast::call_yast_function(mname, :"#{sname}", $1, $2.to_i, *args) end elsif stype == :variable m.define_singleton_method(sname) do Yast::call_yast_function(mname, :"#{sname}") end m.define_method("#{sname}=") do |value| Yast::call_yast_function(mname, :"#{sname}", value) end end end base.const_set(modules.last, m) unless base.constants.include?(modules.last.to_sym) end |
.include(target, path) ⇒ Object
use "lib" directory where you can place common ruby code without any special handling.
includes module from include directory. given include must satisfied few restrictions. 1) file must contain module enclosed in Yast namespace with name constructed from path and its name it is constructed that all parts is upcased and also all [-_.] is replaced and next character must be upper case. At the end is appended Include string example in file network/udev_lan.source.rb must be module Yast::NetworkUdevLanSourceInclude 2) initialization of module must be in method with prefix initialize and rest is translated path, where all [-./] is replaced by underscore. Method take one parameter that is propagated target param. example in file network/udev_lan.source.rb initialization method will be initialize_network_udev_lan_source
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'src/ruby/yast/yast.rb', line 123 def self.include(target, path) path_without_suffix = path.sub(/\.rb$/, "") module_name = path_without_suffix .gsub(/^./, &:upcase) .gsub(/\/./) { |s| s[1].upcase } .gsub(/[-_.]./) { |s| s[1].upcase } + "Include" loaded = Yast.constants.include? module_name.to_sym unless loaded path = find_include_file path require path end mod = Yast.const_get module_name # if never included, then include target.class.send(:include, mod) unless target.class.include?(mod) encoded_name = path_without_suffix.gsub(/[-.\/]/, "_") initialized_variable = "@" + encoded_name + "initialized" method_name = "initialize_" + encoded_name # tricky condition. Here collide two yast features that had old ycp # 1) in clients reapeated call results in new client object, but client base class # is already defined, so not needed to include again, but it's # needed to be reinitialized, so we need to call initialization method # even if module is already included # 2) if there is multi include, then only first one must call initialization # because other calls are ignored if target.respond_to?(method_name.to_sym) && !target.instance_variable_defined?(initialized_variable) # allways set initialized before method call otherwise endless loop in # circle include calls target.instance_variable_set(initialized_variable, true) target.send(method_name.to_sym, target) end end |
.path(value) ⇒ Object
shortcut to construct new Yast path
44 45 46 47 48 49 50 51 52 53 |
# File 'src/ruby/yast/yast.rb', line 44 module_function def path(value) case value when Yast::Path value when ::String Path.new(value) else raise ArgumentError, "Argument #{value.inspect} is neither a ::String or a Yast::Path" end end |
.term(*args) ⇒ Object
shortcut to construct new Yast term
23 24 25 |
# File 'src/ruby/yast/yast.rb', line 23 module_function def term(*args) Term.new(*args) end |
.y2debug(*args) ⇒ Object
write to log debug message with arguments formated by Yast::Builtins.sformat
48 49 50 |
# File 'src/ruby/yast/logger.rb', line 48 module_function def y2debug(*args) y2_logger_helper(0, args) end |
.y2error(*args) ⇒ Object
write to log error message with arguments formated by Yast::Builtins.sformat
63 64 65 |
# File 'src/ruby/yast/logger.rb', line 63 module_function def y2error(*args) y2_logger_helper(3, args) end |
.y2internal(*args) ⇒ Object
write to log internal error message with arguments formated by Yast::Builtins.sformat
74 75 76 |
# File 'src/ruby/yast/logger.rb', line 74 module_function def y2internal(*args) y2_logger_helper(5, args) end |
.y2milestone(*args) ⇒ Object
write to log milestone message with arguments formated by Yast::Builtins.sformat
53 54 55 |
# File 'src/ruby/yast/logger.rb', line 53 module_function def y2milestone(*args) y2_logger_helper(1, args) end |
.y2security(*args) ⇒ Object
make it clear what is supposed to write to this level
write to log security message with arguments formated by Yast::Builtins.sformat
69 70 71 |
# File 'src/ruby/yast/logger.rb', line 69 module_function def y2security(*args) y2_logger_helper(4, args) end |
.y2warning(*args) ⇒ Object
write to log warning message with arguments formated by Yast::Builtins.sformat
58 59 60 |
# File 'src/ruby/yast/logger.rb', line 58 module_function def y2warning(*args) y2_logger_helper(2, args) end |