Class: CFA::Grub2::Default::KernelParams::ParamTree

Inherits:
Object
  • Object
show all
Defined in:
lib/cfa/grub2/default.rb

Overview

Represents parsed kernel parameters tree. Parses in initialization and backserilized by ‘to_string`. TODO: replace it via augeas parser when someone write lense

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ ParamTree

Returns a new instance of ParamTree.



236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/cfa/grub2/default.rb', line 236

def initialize(line)
  pairs = (line || "").split(/\s/)
                      .reject(&:empty?)
                      .map { |e| e.split("=", 2) }

  @data = pairs.map do |k, v|
    {
      key:       k,
      value:     v || true, # kernel param without value have true
      operation: :keep
    }
  end
end

Instance Method Details

#all_dataObject



266
267
268
# File 'lib/cfa/grub2/default.rb', line 266

def all_data
  @data
end

#dataObject



262
263
264
# File 'lib/cfa/grub2/default.rb', line 262

def data
  @data.reject { |e| e[:operation] == :remove }.freeze
end

#to_stringObject



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/cfa/grub2/default.rb', line 250

def to_string
  snippets = data.map do |e|
    if e[:value] == true
      e[:key]
    else
      "#{e[:key]}=#{e[:value]}"
    end
  end

  snippets.join(" ")
end