Class: CFA::SystemdBoot

Inherits:
BaseModel
  • Object
show all
Extended by:
Yast::Logger
Includes:
Yast::Logger
Defined in:
src/lib/cfa/systemd_boot.rb

Overview

CFA based class to handle systemd-boot configuration file

Examples:

Reading a value

file = CFA::SystemdBoot.new
file.load
file.menue_timeout #=> 10

Writing a value

file = CFA::SystemdBoot.new
file.menue_timeout = 5
file.save

Loading shortcut

file = CFA::SystemdBoot.load
file.menue_timeout #=> 10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_handler: Yast::TargetFile, file_path: PATH) ⇒ SystemdBoot

Constructor

Parameters:

  • file_handler (#read, #write) (defaults to: Yast::TargetFile)

    something able to read/write a string (like File)

  • file_path (String) (defaults to: PATH)

    File path

See Also:

  • BaseModel#initialize


75
76
77
# File 'src/lib/cfa/systemd_boot.rb', line 75

def initialize(file_handler: Yast::TargetFile, file_path: PATH)
  super(AugeasParser.new(LENS), file_path, file_handler: file_handler)
end

Class Method Details

.load(file_handler: Yast::TargetFile, file_path: PATH) ⇒ SystemdBoot

Instantiates and loads a file when possible

This method is basically a shortcut to instantiate and load the content in just one call.

Parameters:

  • file_handler (#read, #write) (defaults to: Yast::TargetFile)

    something able to read/write a string (like File)

  • file_path (String) (defaults to: PATH)

    File path

Returns:

  • (SystemdBoot)

    File with the already loaded content



60
61
62
63
64
65
66
67
# File 'src/lib/cfa/systemd_boot.rb', line 60

def self.load(file_handler: Yast::TargetFile, file_path: PATH)
  file = new(file_path: file_path, file_handler: file_handler)
  file.tap(&:load)
rescue Errno::ENOENT
  log.info("#{file_path} couldn't be loaded. Probably the file does not exist yet.")

  file
end

Instance Method Details

#saveObject



79
80
81
82
83
84
85
86
87
88
89
# File 'src/lib/cfa/systemd_boot.rb', line 79

def save
  directory = File.dirname(@file_path)
  if !Yast::FileUtils.IsDirectory(directory)
    Yast::Execute.on_target("/usr/bin/mkdir", "--parents",
      directory)
  end
  super
rescue Errno::EACCES
  log.info("Permission denied when writting to #{@file_path}")
  false
end