lib/linux_admin/fstab.rb in linux_admin-0.2.0 vs lib/linux_admin/fstab.rb in linux_admin-0.2.1

- old
+ new

@@ -11,10 +11,30 @@ attr_accessor :mount_point attr_accessor :fs_type attr_accessor :mount_options attr_accessor :dumpable attr_accessor :fsck_order + + def initialize(args = {}) + @device = args[:device] + @mount_point = args[:mount_point] + @fs_type = args[:fs_type] + @mount_options = args[:mount_options] + @dumpable = args[:dumpable] + @fsck_order = args[:fsck_order] + end + + def self.from_line(fstab_line) + columns = fstab_line.chomp.split + FSTabEntry.new :device => columns[0], + :mount_point => columns[1], + :fs_type => columns[2], + :mount_options => columns[3], + :dumpable => columns[4].to_i, + :fsck_order => columns[5].to_i + + end end class FSTab < LinuxAdmin include Singleton @@ -33,26 +53,23 @@ self end private - def refresh - @entries = [] - f = File.read('/etc/fstab') - f.each_line { |line| - first_char = line.strip[0] - if first_char != '#' && first_char !~ /\s/ - columns = line.split - entry = FSTabEntry.new - entry.device = columns[0] - entry.mount_point = columns[1] - entry.fs_type = columns[2] - entry.mount_options = columns[3] - entry.dumpable = columns[4].to_i - entry.fsck_order = columns[5].to_i - @entries << entry - end + def read + contents = File.read('/etc/fstab') + contents = contents.lines.to_a + contents.reject! { |line| + first_char = line.strip[0] + first_char == '#' || first_char =~ /\s/ } - self + contents + end + + def refresh + @entries = + read.collect { |line| + FSTabEntry.from_line line + } end end end