class Mountpoints

#

Constants

DEBUG
#

DEBUG

#
DF_COMMAND
#

DF_COMMAND

#
FDISK_COMMAND
#

FDISK_COMMAND

#
LJUST
#

LJUST

#
N
VERSION
#

Mountpoints::VERSION

#

Public Class Methods

[](be_extra_verbose = :normal_verbosity) click to toggle source
#

Mountpoints[]

This method will return an array such as:

["/Mount/USB1/"]

In other words, it will be a silent result.

Mountpoints[] Mountpoints

#
# File lib/mountpoints/mountpoints.rb, line 222
def self.[](be_extra_verbose = :normal_verbosity)
  if be_extra_verbose == :be_extra_verbose
    _ = Mountpoints.new(be_extra_verbose)
    _.report_result
  else
    Mountpoints.new(be_extra_verbose).array_mountpoints
  end
end
is_any_mountpoint_available?() click to toggle source
#

Mountpoints.is_any_mountpoint_available?

#
# File lib/mountpoints/mountpoints.rb, line 234
def self.is_any_mountpoint_available?
  !Mountpoints.new(:be_quiet).array_mountpoints.empty?
end
new( run_already = true ) click to toggle source
#

initialize

If the first argument is :be_extra_verbose then we will show more information.

#
# File lib/mountpoints/mountpoints.rb, line 66
def initialize(
    run_already = true
  )
  reset
  case run_already
  when :be_extra_verbose
    @be_extra_verbose = true 
    run_already = true
  when :normal_verbosity # Simply pass through here.
  end
  run if run_already
end
report() click to toggle source
#

Mountpoints.report

#
# File lib/mountpoints/mountpoints.rb, line 207
def self.report
  Mountpoints[:be_extra_verbose]
end
show() click to toggle source
#

Mountpoints.show

#
# File lib/mountpoints/mountpoints.rb, line 241
def self.show
  Mountpoints.new :be_extra_verbose
end

Public Instance Methods

array_mountpoints()
Alias for: array_mountpoints?
array_mountpoints?() click to toggle source
#

array_mountpoints?

#
# File lib/mountpoints/mountpoints.rb, line 193
def array_mountpoints? # This should always be an Array.
  @array_mountpoints
end
Also aliased as: array_mountpoints
debug?() click to toggle source
#

debug?

#
# File lib/mountpoints/mountpoints.rb, line 186
def debug?
  DEBUG
end
determine_mountpoints() click to toggle source
#

determine_mountpoints

The @array_mountpoints will keep all directory-names with a trailing '/'. In other words, the mountpoints will be stored there.

#
# File lib/mountpoints/mountpoints.rb, line 122
def determine_mountpoints
  @array_mountpoints = @result.map {|entry| entry.first }
end
determine_result() click to toggle source
#

determine_result

This method will run the df-command.

#
# File lib/mountpoints/mountpoints.rb, line 131
def determine_result
  if debug?
    e "Now running this command: #{sfancy(@command_to_run)}"
  end
  @result = `#{@command_to_run}`.split(N) # This will keep the main result.
  _ = @result.reject {|entry| !entry.include? '/Mount' }.
              reject {|entry| !entry.include? 'USB' }
  # ======================================================================= #
  # At this point, we have only the entries that have /Mount as part
  # of their name.
  # ======================================================================= #
  _.map! {|entry|
    splitted = entry.split(' ')
    # filesize =
    entry = [ splitted[-1], splitted.first, splitted[2] ] 
  }
  set_result _ # Now contains the mountpoints here.
end
rds(i) click to toggle source
#

rds

#
# File lib/mountpoints/mountpoints.rb, line 112
def rds(i)
  i.squeeze('/')
end
report_colourized_result()
Alias for: report_result
report_result() click to toggle source
#

report_result

#
# File lib/mountpoints/mountpoints.rb, line 153
def report_result
  if @be_extra_verbose
    if result?.empty?
      opn; e 'We did not find any mount point. We conclude that '\
             'no USB device is mounted.'
    else
      opn; e 'We did find these mount points:'
      e
      result?.each {|line|
        filesize       = line[2]
        name_of_device = line[1]
        mounted_here   = line[0]
        efancy '  '+mounted_here.ljust(LJUST)+'   '+
               swarn(name_of_device)+' '+
               '('+Colours.green(filesize)+')'
      }
      e
    end 
  else # else we report "normally.
    e result?.join(N)
  end
end
Also aliased as: report_colourized_result
reset() click to toggle source
#

reset

#
# File lib/mountpoints/mountpoints.rb, line 82
def reset
  @be_extra_verbose = false
  @command_to_run = DF_COMMAND # This command will be run.
end
result()
Alias for: result?
result?() click to toggle source
#

result?

#
# File lib/mountpoints/mountpoints.rb, line 179
def result?
  @result
end
Also aliased as: result
run() click to toggle source
#

run (run tag)

#
# File lib/mountpoints/mountpoints.rb, line 200
def run
  determine_result
end
set_result(i) click to toggle source
#

set_result

#
# File lib/mountpoints/mountpoints.rb, line 90
def set_result(i)
  if i.is_a? String
    i << '/' unless i.end_with? '/'
  elsif i.is_a? Array
    # ===================================================================== #
    # Do not flatten here as we may have more than one Array-entry.
    # ===================================================================== #
    i.map! {|entry|
      entry[0] = rds(entry.first+'/')
      entry
    } # We want directories to end in a '/'.
  end
  if i.is_a? Array
    i.sort_by! {|entry| entry }
  end
  @result = i # Will include trailing /.
  determine_mountpoints
end