class CFA::Grub2::Default::KernelParams
Represents kernel append line with helpers to easier modification. TODO: handle quoting, maybe have own lense to parse/serialize kernel
params?
Attributes
key[R]
Public Class Methods
new(line, key)
click to toggle source
# File lib/cfa/grub2/default.rb, line 171 def initialize(line, key) @tree = ParamTree.new(line) @key = key end
Public Instance Methods
add_parameter(key, value, placer = AppendPlacer.new)
click to toggle source
Adds new parameter to kernel command line. Uses augeas placers. To replace value use {ReplacePlacer}
# File lib/cfa/grub2/default.rb, line 218 def add_parameter(key, value, placer = AppendPlacer.new) element = placer.new_element(@tree) element[:operation] = :add element[:key] = key element[:value] = value end
empty?()
click to toggle source
checks if there is any parameter
# File lib/cfa/grub2/default.rb, line 186 def empty? serialize.empty? end
parameter(key)
click to toggle source
gets value for parameters. @return possible values are `false` when parameter missing,
`true` when parameter without value placed, string if single instance with value is there and array if multiple instance with values are there.
@example different values
line = "quite console=S0 console=S1 vga=0x400" params = KernelParams.new(line) params.parameter("quite") # => true params.parameter("verbose") # => false params.parameter("vga") # => "0x400" params.parameter("console") # => ["S0", "S1"]
# File lib/cfa/grub2/default.rb, line 204 def parameter(key) values = @tree.data .select { |e| e[:key] == key } .map { |e| e[:value] } return false if values.empty? return values if values.size > 1 return true if values.first == true values.first end
remove_parameter(matcher)
click to toggle source
Removes parameter from kernel command line. @param matcher [Matcher] to find entry to remove
# File lib/cfa/grub2/default.rb, line 228 def remove_parameter(matcher) @tree.data.select(&matcher).each { |e| e[:operation] = :remove } end
replace(line)
click to toggle source
replaces kernel params with passed line
# File lib/cfa/grub2/default.rb, line 181 def replace(line) @tree = ParamTree.new(line) end
serialize()
click to toggle source
# File lib/cfa/grub2/default.rb, line 176 def serialize @tree.to_string end