Class: Kanrisuru::Remote::Fstab
- Inherits:
-
Object
- Object
- Kanrisuru::Remote::Fstab
- Includes:
- Enumerable
- Defined in:
- lib/kanrisuru/remote/fstab.rb,
lib/kanrisuru/remote/fstab/entry.rb,
lib/kanrisuru/remote/fstab/options.rb
Defined Under Namespace
Instance Method Summary collapse
- #<<(entry) ⇒ Object
- #[](device) ⇒ Object
- #append(entry) ⇒ Object
-
#append_file! ⇒ Object
Only append new entries to file.
- #delete(device) ⇒ Object
- #each(&block) ⇒ Object
- #find_device(device) ⇒ Object
- #get_entry(device) ⇒ Object
-
#initialize(host, path = '/etc/fstab') ⇒ Fstab
constructor
A new instance of Fstab.
- #inspect ⇒ Object
- #reload! ⇒ Object
- #to_s ⇒ Object
-
#write_file! ⇒ Object
Rewrites entire fstab file with new and old entries.
Constructor Details
#initialize(host, path = '/etc/fstab') ⇒ Fstab
Returns a new instance of Fstab.
11 12 13 14 15 16 17 18 |
# File 'lib/kanrisuru/remote/fstab.rb', line 11 def initialize(host, path = '/etc/fstab') @host = host @path = path @file = nil @backup = nil init_from_os end |
Instance Method Details
#<<(entry) ⇒ Object
45 46 47 |
# File 'lib/kanrisuru/remote/fstab.rb', line 45 def <<(entry) append(entry) end |
#[](device) ⇒ Object
20 21 22 |
# File 'lib/kanrisuru/remote/fstab.rb', line 20 def [](device) get_entry(device) end |
#append(entry) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kanrisuru/remote/fstab.rb', line 49 def append(entry) if entry.instance_of?(Kanrisuru::Remote::Fstab::Entry) return if @entries.key?(entry.device) elsif entry.instance_of?(String) entry = Kanrisuru::Remote::Fstab::Entry.new(host: @host, line: entry) return if @entries.key?(entry.device) else raise ArgumentError, 'Invalid entry type' end @entries[entry.device] = { entry: entry, new: true } nil end |
#append_file! ⇒ Object
Only append new entries to file
76 77 78 79 80 81 82 83 84 |
# File 'lib/kanrisuru/remote/fstab.rb', line 76 def append_file! @file.append do |f| @entries.each do |_, entry| f << entry[:entry].to_s if entry[:new] end end reload! end |
#delete(device) ⇒ Object
24 25 26 27 28 |
# File 'lib/kanrisuru/remote/fstab.rb', line 24 def delete(device) return false unless @entries.key?(device) @entries.delete(device) end |
#each(&block) ⇒ Object
69 70 71 72 73 |
# File 'lib/kanrisuru/remote/fstab.rb', line 69 def each(&block) @entries.each do |_, entry| block.call(entry[:entry]) end end |
#find_device(device) ⇒ Object
67 |
# File 'lib/kanrisuru/remote/fstab.rb', line 67 def find_device(device); end |
#get_entry(device) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kanrisuru/remote/fstab.rb', line 30 def get_entry(device) result = @entries[device] return result[:entry] if result result = nil ## Lookup by uuid or label @entries.each do |_, entry| result = entry[:entry] if !@result && (entry[:entry].uuid == device || entry[:entry].label == device) end result end |
#inspect ⇒ Object
110 111 112 113 |
# File 'lib/kanrisuru/remote/fstab.rb', line 110 def inspect format('#<Kanrisuru::Remote::Fstab:0x%<object_id>s @path=%<path>s @entries=%<entries>s>', object_id: object_id, path: @path, entries: @entries) end |
#reload! ⇒ Object
106 107 108 |
# File 'lib/kanrisuru/remote/fstab.rb', line 106 def reload! init_from_os end |
#to_s ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/kanrisuru/remote/fstab.rb', line 97 def to_s lines = [] @entries.each do |_, entry| lines << entry[:entry].to_s end lines.join("\n") end |
#write_file! ⇒ Object
Rewrites entire fstab file with new and old entries
87 88 89 90 91 92 93 94 95 |
# File 'lib/kanrisuru/remote/fstab.rb', line 87 def write_file! @file.write do |f| @entries.each do |_, entry| f << entry[:entry].to_s end end reload! end |