Class: Y2Network::Driver
- Inherits:
-
Object
- Object
- Y2Network::Driver
- Includes:
- CanBeCopied, Yast2::Equatable
- Defined in:
- src/lib/y2network/driver.rb
Overview
This class represents a driver for an interface
It is composed of a kernel module name and a string representing the module options
Instance Attribute Summary collapse
-
#name ⇒ String
Kernel module name.
-
#params ⇒ String
Kernel module parameters.
Class Method Summary collapse
-
.commit ⇒ Object
Commits drivers options to disk.
-
.from_system(name) ⇒ Object
Returns a driver using the information from the system.
-
.write_options(drivers) ⇒ Object
Writes driver options to the underlying system.
Instance Method Summary collapse
-
#initialize(name, params = "") ⇒ Driver
constructor
Constructor.
-
#write_options ⇒ Object
Adds driver parameters to be written to the underlying system.
Methods included from CanBeCopied
Constructor Details
#initialize(name, params = "") ⇒ Driver
Constructor
67 68 69 70 |
# File 'src/lib/y2network/driver.rb', line 67 def initialize(name, params = "") @name = name @params = params end |
Instance Attribute Details
#name ⇒ String
Returns Kernel module name.
57 58 59 |
# File 'src/lib/y2network/driver.rb', line 57 def name @name end |
#params ⇒ String
Returns Kernel module parameters.
59 60 61 |
# File 'src/lib/y2network/driver.rb', line 59 def params @params end |
Class Method Details
.commit ⇒ Object
Commits drivers options to disk
51 52 53 |
# File 'src/lib/y2network/driver.rb', line 51 def commit Yast::SCR.Write(Yast::Path.new(".modules"), nil) end |
.from_system(name) ⇒ Object
Returns a driver using the information from the system
36 37 38 39 40 |
# File 'src/lib/y2network/driver.rb', line 36 def from_system(name) params = Yast::SCR.Read(Yast::Path.new(".modules.options.#{name}")) params_string = params.map { |k, v| "#{k}=#{v}" }.join(" ") new(name, params_string) end |
.write_options(drivers) ⇒ Object
Writes driver options to the underlying system
45 46 47 48 |
# File 'src/lib/y2network/driver.rb', line 45 def (drivers) drivers.each(&:write_options) commit end |
Instance Method Details
#write_options ⇒ Object
Adds driver parameters to be written to the underlying system
Parameters are not written to disk until Y2Network::Driver.commit is called. The reason is that writing them is an expensive operation, so it is better to write parameters for all drivers at the same time.
You might prefer to use write_options instead.
81 82 83 84 85 86 87 88 |
# File 'src/lib/y2network/driver.rb', line 81 def parts = params.split(/ +/) params_hash = parts.each_with_object({}) do |param, hash| key, value = param.split("=") hash[key] = value.to_s end Yast::SCR.Write(Yast::Path.new(".modules.options.#{name}"), params_hash) end |