class RBT::Cookbooks::FindAllArchiveTypes

Constants

EXIT_ON_MISSING_ARCHIVE
#

EXIT_ON_MISSING_ARCHIVE

#
LJUST
#

LJUST

#
REPORT_POSSIBLE_PROBLEM
#

REPORT_POSSIBLE_PROBLEM

#

Public Class Methods

new( run_already = true ) click to toggle source
#

initialize

This class does not require any argument input.

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 49
def initialize(
    run_already = true
  )
  reset
  run if run_already
end

Public Instance Methods

add_count_for(i) click to toggle source
#

add_count_for

Use this method to keep track of all the entries that are part of our @hash. We will count +1 for each of .zip, .tar.bz2, .tar.gz and .tar.xz.

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 109
def add_count_for(i)
  case i # case tag
  when /\.zip$/
    @hash[ZIP] += 1
  when /\.tar\.bz2$/
    @hash[TAR_BZ2] += 1
  when /\.tar\.gz$/
    @hash[TAR_GZ] += 1
  when /\.tar\.xz$/
    @hash[TAR_XZ] += 1
  end
end
all_directories?() click to toggle source
#

all_directories?

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 98
def all_directories?
  @all_directories
end
menu( i = nil ) click to toggle source
#

menu (case tag, menu tag)

#
obtain_all_directories_from_the_source_directory() click to toggle source
#

obtain_all_directories_from_the_source_directory

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 148
def obtain_all_directories_from_the_source_directory
  @all_directories = Dir["#{@base_directory}*/"].reject {|entry|
    ! File.directory? entry
  }.sort
end
process_every_directory() click to toggle source
#

process_every_directory

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 125
def process_every_directory
  all_directories?.each {|dir|
    found_entry = Dir["#{dir}*"].first
    if found_entry.nil?
      if @report_possible_problem
        opne 'There might be an error at `'+sdir(dir)+'`.'
      end if be_verbose? # Only if we are verbose.
      exit if @exit_on_missing_archive
    else
      if    found_entry.include? TAR_BZ2
        @array_for_tar_bz2 << found_entry
      elsif found_entry.include? TAR_GZ
        @array_for_tar_gz  << found_entry
      end
      _ = File.basename(found_entry)
      add_count_for(_)
    end
  }
end
report()
Alias for: show_results
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 59
def reset
  super()
  infer_the_namespace
  set_base_directory
  # ======================================================================= #
  # === @exit_on_missing_archive
  # ======================================================================= #
  @exit_on_missing_archive = EXIT_ON_MISSING_ARCHIVE
  # ======================================================================= #
  # === @report_possible_problem
  # ======================================================================= #
  @report_possible_problem = REPORT_POSSIBLE_PROBLEM
  # ======================================================================= #
  # === @hash
  # ======================================================================= #
  @hash = {}
  @hash.default = 0 # We start counting at 0.
  # ======================================================================= #
  # === @array_for_tar_bz2
  # ======================================================================= #
  @array_for_tar_bz2 = [] # Store .tar.bz2 files here.
  # ======================================================================= #
  # === @array_for_tar_gz
  # ======================================================================= #
  @array_for_tar_gz  = [] # Store .tar.gz files here.
end
run() click to toggle source
#

run

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 227
def run
  obtain_all_directories_from_the_source_directory
  process_every_directory
end
run_and_report() click to toggle source
#

run_and_report

Bundle run() and report() together.

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 219
def run_and_report
  run
  report
end
set_base_directory( i = source_directory? ) click to toggle source
#

set_base_directory

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 89
def set_base_directory(
    i = source_directory?
  )
  @base_directory = i
end
show_results() click to toggle source
#

show_results

This method will show the results, in a pretty-printed fashion.

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 206
def show_results
  opne 'We found these results:'
  e '  '+(TAR_XZ+': ' ).ljust(LJUST)+sfancy(@hash[TAR_XZ].to_s)
  e '  '+(TAR_BZ2+': ').ljust(LJUST)+sfancy(@hash[TAR_BZ2].to_s)
  e '  '+(TAR_GZ+': ' ).ljust(LJUST)+sfancy(@hash[TAR_GZ].to_s)
  e '  '+(ZIP+': '    ).ljust(LJUST)+sfancy(@hash[ZIP].to_s)
end
Also aliased as: report
show_results_for( i = TAR_BZ2 ) click to toggle source
#

show_results_for

#
# File lib/rbt/cookbooks/find_all_archive_types.rb, line 178
def show_results_for(
    i = TAR_BZ2
  )
  case i
  when TAR_GZ
    if @array_for_tar_gz.empty?
      opne 'No '+swarn('.tar.gz')+' entries were found.'
    else
      @array_for_tar_gz.each {|entry|
        e swarn('  '+entry)
      }
    end
  when TAR_BZ2
    if @array_for_tar_bz2.empty?
      opne 'No .tar.bz2 entries were found.'
    else
      @array_for_tar_bz2.each {|entry|
        e swarn('  '+entry)
      }
    end
  end 
end