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.



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

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



264
265
266
# File 'lib/cfa/grub2/default.rb', line 264

def all_data
  @data
end

#dataObject



260
261
262
# File 'lib/cfa/grub2/default.rb', line 260

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

#to_stringObject



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

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

  snippets.join(" ")
end