Class: Y2Network::Driver

Inherits:
Object
  • Object
show all
Includes:
CanBeCopied
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CanBeCopied

#copy

Constructor Details

#initialize(name, params = "") ⇒ Driver

Constructor


63
64
65
66
# File 'src/lib/y2network/driver.rb', line 63

def initialize(name, params = "")
  @name = name
  @params = params
end

Instance Attribute Details

#nameString


55
56
57
# File 'src/lib/y2network/driver.rb', line 55

def name
  @name
end

#paramsString


57
58
59
# File 'src/lib/y2network/driver.rb', line 57

def params
  @params
end

Class Method Details

.commitObject

Commits drivers options to disk


49
50
51
# File 'src/lib/y2network/driver.rb', line 49

def commit
  Yast::SCR.Write(Yast::Path.new(".modules"), nil)
end

.from_system(name) ⇒ Object

Returns a driver using the information from the system


34
35
36
37
38
# File 'src/lib/y2network/driver.rb', line 34

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


43
44
45
46
# File 'src/lib/y2network/driver.rb', line 43

def write_options(drivers)
  drivers.each(&:write_options)
  commit
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two drivers are equal


72
73
74
75
# File 'src/lib/y2network/driver.rb', line 72

def ==(other)
  return false unless other.is_a?(Driver)
  name == other.name && params == other.params
end

#write_optionsObject

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.

See Also:


86
87
88
89
90
91
92
93
# File 'src/lib/y2network/driver.rb', line 86

def write_options
  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