class Cookbooks::ScanSourceArchive

Constants

ARRAY_SKIP_THESE_DIRECTORIES
#

ARRAY_SKIP_THESE_DIRECTORIES

Next comes a listing of Sub-Directories to skip (forbidden dirs). Careful with what you enter here.

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

new(run_already = true) click to toggle source
#

initialize

#
Calls superclass method
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 60
def initialize(run_already = true)
  register_sigint
  super()
  reset
  run if run_already
end

Public Instance Methods

array_registered_files()
array_registered_files?() click to toggle source
#

#array_registered_files?

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 171
def array_registered_files?
  @array_registered_files
end
Also aliased as: array_registered_files
files?() click to toggle source
#

files?

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 164
def files?
  @array_registered_files
end
forbidden?(i) click to toggle source
#

forbidden?

Skip directories listed in our array.

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 154
def forbidden?(i)
  ARRAY_SKIP_THESE_DIRECTORIES.any? { |entry|
    return true if i.include? entry
  }
  return false
end
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 200
def opnn
  super(NAMESPACE)
end
process_registered_programs(i = files?) click to toggle source
#

#process_registered_programs

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 185
def process_registered_programs(i = files?)
  i.each { |name_of_program, real_location|
    @cookbook_dataset = ::Cookbooks::Cookbook.new(name_of_program) { :bypass_menu }
    if @cookbook_dataset.program_was_found?
      # opnn; e sfancy(name_of_program)+' is included.' Then be silent.
    else # Else it is not included.
      opnn; e swarn('`'+sfancy(name_of_program.to_s)+'` is not included.')
      opnn; e '  It can be found at `'+sfile(real_location)+'`.'
    end
  }
end
query_database()
Alias for: query_database?
query_database?() click to toggle source
#

#query_database?

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 178
def query_database?
  @query_database
end
Also aliased as: query_database
register_file(f, real_location) click to toggle source
#

#register_file

Simply append to @array_registered_file.

The second argument shall specify the target location.

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 97
def register_file(f, real_location)
  @array_registered_files << [
    f, real_location
  ] #unless @array_registered_files
end
reset() click to toggle source
#

reset

#
Calls superclass method Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 70
def reset
  super()
  @cookbook_dataset = nil
  @array_registered_files = [] # Keep them registered.
end
run( target = source_directory? )
Alias for: scan
scan( target = source_directory? ) click to toggle source
#

scan

This is the actual scanning action.

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 108
def scan(
    target = source_directory?
  )
  set_target_directory(target)
  opnn; e "Scanning through `#{sdir(target_directory?)}"\
          "` and all of its subdirectories next."
  opnn; e 'This may take a while - please be patient.'+N
  all_files = Dir["#{target_directory?}**/*"].sort
  # ======================================================================= #
  # Filter away directories.
  # ======================================================================= #
  all_files.reject! {|entry| File.directory? entry }
  opnn; e simp(all_files.size.to_s)+' entries (== files) were found.'
  all_files.each { |file|
    original_file = file.to_s.dup
    next if ! file.include? '-'
    next if forbidden?(file)
    file = File.basename(file).downcase
    # ======================================================================= #
    # Obtain only the assumed "program name".
    # ======================================================================= #
    file = ProgramInformation::ProgramInformation.new(file).return_name
    _ = Cookbooks::Cookbook.new(file) { :bypass_menu }
    _ = file.to_s.gsub(/-/,'').downcase.gsub(/_/,'')
    if _.empty?
      opnn; e "Something went wrong for #{sfile(file)},#{sfancy(original_file)} (#{simp(_)})."
      opnn; e 'Please correct this mistake.'
      exit
    end
    begin
      register_file(_, file) # Register the file here.
    rescue Exception => error
      opnn; e 'An error happened (error type: '+sfancy(error.class.to_s)+
              ') at line '+swarn(__LINE__.to_s)
      opnn; e 'The original_file entry was: '+simp(original_file.to_s)
      pp error
    end
  }
  process_registered_programs
end
Also aliased as: run
set_target_directory(i) click to toggle source
#

#set_target_directory

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 79
def set_target_directory(i)
  @target_directory = i
end
target_directory()
Alias for: target_directory?
target_directory?() click to toggle source
#

#target_directory?

#
# File lib/cookbooks/utility_scripts/scan_source_archive.rb, line 86
def target_directory?
  @target_directory
end
Also aliased as: target_directory