Module: LinuxMountParser
- Defined in:
- lib/utils/parser.rb
Instance Method Summary collapse
- 
  
    
      #includes_whitespaces?(mount_line)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Device-/Sharename or Mountpoint includes whitespaces?. 
- 
  
    
      #parse_mount_options(mount_line, compatibility = false)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    this parses the output of mount command (only tested on linux) this method expects only one line of the mount output. 
Instance Method Details
#includes_whitespaces?(mount_line) ⇒ Boolean
Device-/Sharename or Mountpoint includes whitespaces?
| 109 110 111 112 | # File 'lib/utils/parser.rb', line 109 def includes_whitespaces?(mount_line) ws = mount_line.match(/^(.+)\son\s(.+)\stype\s.*$/) ws.captures[0].include?(' ') or ws.captures[1].include?(' ') end | 
#parse_mount_options(mount_line, compatibility = false) ⇒ Object
this parses the output of mount command (only tested on linux) this method expects only one line of the mount output
| 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | # File 'lib/utils/parser.rb', line 69 def (mount_line, compatibility = false) if includes_whitespaces?(mount_line) # Device-/Sharenames and Mountpoints including whitespaces require special treatment: # We use the keyword ' type ' to split up and rebuild the desired array of fields type_split = mount_line.split(' type ') fs_path = type_split[0] other_opts = type_split[1] fs, path = fs_path.match(%r{^(.+?)\son\s(/.+?)$}).captures mount = [fs, 'on', path, 'type'] mount.concat(other_opts.scan(/\S+/)) else # ... otherwise we just split the fields by whitespaces mount = mount_line.scan(/\S+/) end # parse device and type = { device: mount[0], type: mount[4] } if compatibility == false # parse options as array [:options] = mount[5].gsub(/\(|\)/, '').split(',') else # parse options as serverspec uses it, tbis is deprecated [:options] = {} mount[5].gsub(/\(|\)/, '').split(',').each do |option| name, val = option.split('=') if val.nil? val = true elsif val =~ /^\d+$/ # parse numbers val = val.to_i end [:options][name.to_sym] = val end end end |