Class: CFA::Grub2::Default::KernelParams
- Inherits:
-
Object
- Object
- CFA::Grub2::Default::KernelParams
- Defined in:
- lib/cfa/grub2/default.rb
Overview
Represents kernel append line with helpers to easier modification. TODO: handle quoting, maybe have own lense to parse/serialize kernel
params?
Defined Under Namespace
Classes: ParamTree
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#add_parameter(key, value, placer = AppendPlacer.new) ⇒ Object
Adds new parameter to kernel command line.
-
#empty? ⇒ Boolean
checks if there is any parameter.
-
#initialize(line, key) ⇒ KernelParams
constructor
A new instance of KernelParams.
-
#parameter(key) ⇒ Object
gets value for parameters.
-
#remove_parameter(matcher) ⇒ Object
Removes parameter from kernel command line.
-
#replace(line) ⇒ Object
replaces kernel params with passed line.
- #serialize ⇒ Object
Constructor Details
#initialize(line, key) ⇒ KernelParams
Returns a new instance of KernelParams.
171 172 173 174 |
# File 'lib/cfa/grub2/default.rb', line 171 def initialize(line, key) @tree = ParamTree.new(line) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
169 170 171 |
# File 'lib/cfa/grub2/default.rb', line 169 def key @key end |
Instance Method Details
#add_parameter(key, value, placer = AppendPlacer.new) ⇒ Object
Adds new parameter to kernel command line. Uses augeas placers. To replace value use ReplacePlacer
218 219 220 221 222 223 224 |
# 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? ⇒ Boolean
checks if there is any parameter
186 187 188 |
# File 'lib/cfa/grub2/default.rb', line 186 def empty? serialize.empty? end |
#parameter(key) ⇒ Object
gets value for parameters.
204 205 206 207 208 209 210 211 212 213 214 |
# 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) ⇒ Object
Removes parameter from kernel command line.
228 229 230 |
# File 'lib/cfa/grub2/default.rb', line 228 def remove_parameter(matcher) @tree.data.select(&matcher).each { |e| e[:operation] = :remove } end |
#replace(line) ⇒ Object
replaces kernel params with passed line
181 182 183 |
# File 'lib/cfa/grub2/default.rb', line 181 def replace(line) @tree = ParamTree.new(line) end |
#serialize ⇒ Object
176 177 178 |
# File 'lib/cfa/grub2/default.rb', line 176 def serialize @tree.to_string end |