Class: Y2Network::Startmode

Inherits:
Object
  • Object
show all
Includes:
Yast2::Equatable, Yast::Logger
Defined in:
src/lib/y2network/startmode.rb

Overview

Base class for startmode. It allows to create new one according to name or anlist all. Its child have to define to_human_string method and possibly its own specialized attributes. TODO: as backends differs, we probably also need to have flag there to which backends mode exists

Constant Summary collapse

ALIASES =

To be backward compliant 'boot', 'on' and 'onboot' are aliases for 'auto' (bsc#1186910)

{
  "boot"   => "auto",
  "onboot" => "auto",
  "on"     => "auto"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, alias_name: nil) ⇒ Startmode

Returns a new instance of Startmode.



47
48
49
50
# File 'src/lib/y2network/startmode.rb', line 47

def initialize(name, alias_name: nil)
  @name = name
  @alias_name = alias_name
end

Instance Attribute Details

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



41
42
43
# File 'src/lib/y2network/startmode.rb', line 41

def alias_name
  @alias_name
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



40
41
42
# File 'src/lib/y2network/startmode.rb', line 40

def name
  @name
end

Class Method Details

.allObject



66
67
68
69
# File 'src/lib/y2network/startmode.rb', line 66

def self.all
  require "y2network/startmodes"
  Startmodes.constants.map { |c| Startmodes.const_get(c).new }
end

.create(mode) ⇒ Object

gets new instance of startmode for given type and its params



53
54
55
56
57
58
59
60
61
62
63
64
# File 'src/lib/y2network/startmode.rb', line 53

def self.create(mode)
  name = ALIASES[mode] || mode
  alias_name = ALIASES[mode] ? mode : nil

  # avoid circular dependencies
  require "y2network/startmodes"
  const = Startmodes.const_get(name.capitalize)
  alias_name ? const.new(alias_name: alias_name) : const.new
rescue NameError => e
  log.error "Invalid startmode #{e.inspect}"
  nil
end