Class: GrubEditEnv::GrubEnv
- Inherits:
-
Object
- Object
- GrubEditEnv::GrubEnv
- Defined in:
- lib/grub-editenv-ruby/grubenv.rb
Defined Under Namespace
Classes: FileNotFound
Constant Summary collapse
- ENVBLK_SIGNATURE =
"# GRUB Environment Block\n"
- ENVBLK_SIZE =
1024
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
- #grubenv_path ⇒ Object
-
#initialize(options = {}) ⇒ GrubEnv
constructor
A new instance of GrubEnv.
- #reload ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GrubEnv
Returns a new instance of GrubEnv.
19 20 21 22 23 24 25 26 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 19 def initialize( = {}) @options = self.class..merge() raise "Misconfigured" unless grubenv_path raise FileNotFound, "File #{grubenv_path} was not found!" unless File.file?(grubenv_path) reload end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
17 18 19 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 17 def entries @entries end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 16 def @options end |
Class Method Details
.default_options ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 8 def self. { :envblk_signature => ENVBLK_SIGNATURE, :envblk_size => ENVBLK_SIZE, :grubenv_path => nil } end |
Instance Method Details
#dump ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 46 def dump contents = [:envblk_signature] @entries.each do |key, value| data = "#{key}=#{value}\n" contents << data end contents << "#" while contents.size < [:envblk_size] File.open grubenv_path, "wb" do |f| f << contents end end |
#grubenv_path ⇒ Object
28 29 30 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 28 def grubenv_path [:grubenv_path] end |
#reload ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/grub-editenv-ruby/grubenv.rb', line 32 def reload @entries = nil data = File.read(grubenv_path) raise "Wrong grubenv format on reload!" unless data.start_with?([:envblk_signature]) data[0, [:envblk_signature].size] = '' data.sub!(/#*\z/, "") @entries = {} data.split("\n").each do |line| key, value = line.split("=") @entries[key] = value end end |