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
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
Public Instance Methods
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
determine_mountpoints()
click to toggle source
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
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
result?()
click to toggle source
Also aliased as: result
run()
click to toggle source
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