class RBT::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.

#

Public Class Methods

new( run_already = true ) click to toggle source
#

initialize

#
Calls superclass method RBT::LeanPrototype::new
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 59
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/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 192
def array_registered_files?
  @array_registered_files
end
Also aliased as: array_registered_files
files?() click to toggle source
#

files?

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

forbidden?

Skip directories listed in our array.

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

process_registered_programs

#
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 206
def process_registered_programs(
    i = files?
  )
  available_programs = available_programs?
  i.each { |name_of_the_program, real_location|
    if available_programs.include? name_of_the_program
      # opne sfancy(name_of_program)+' is included.' Then be silent.
    else # Else it is not included.
      opne swarn('`')+
           sfancy(name_of_the_program.to_s)+
           swarn('` is not included.')
      opne "#{rev}It can be found at `#{sfile(real_location)}#{rev}`."
    end
  }
end
query_database()
Alias for: query_database?
query_database?() click to toggle source
#

query_database?

#
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 199
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/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 105
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 RBT::LeanPrototype#reset
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 71
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @cookbook_dataset
  # ======================================================================= #
  @cookbook_dataset = nil
  # ======================================================================= #
  # === @array_registered_files
  # ======================================================================= #
  @array_registered_files = [] # Keep them registered.
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 225
def run
  scan
end
scan( target = source_directory? ) click to toggle source
#

scan

This is the actual scanning action.

#
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 116
def scan(
    target = source_directory?
  )
  set_target_directory(target)
  opne "Scanning through `#{sdir(target_directory?)}"\
       "` and all of its subdirectories next."
  opne "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 }
  # ======================================================================= #
  # Report to the user how many entries were foudn.
  # ======================================================================= #
  opne "#{royalblue(all_files.size.to_s)} entries (== files) were found."
  all_files.each { |file|
    original_file = file.to_s.dup # Keep a reference here.
    next if !file.include? '-'
    next if forbidden?(file)
    file = remove_archive_at_the_end(
      File.basename(file).downcase
    )
    # ===================================================================== #
    # Obtain only the assumed "program name".
    # ===================================================================== #
    name_of_the_program = ProgramInformation::ProgramInformation.new(file).return_name
    name_of_the_program = name_of_the_program.to_s.
                          tr('-','').downcase.
                          tr('_','')
    if name_of_the_program.empty?
      opne "Something went wrong for #{sfile(file)}#{rev}, "\
           "#{sfancy(original_file)} #{rev}(#{simp(name_of_the_program)}#{rev})."
      opne 'Please correct this mistake.'
    elsif file.end_with? '.gem' # Ignore ruby .gem files.
      name_of_the_program = nil
    end
    begin
      # =================================================================== #
      # Register the file here.
      # =================================================================== #
      register_file(
        name_of_the_program, original_file
      ) if name_of_the_program
    rescue Exception => error
      opne 'An error happened (error type: '+sfancy(error.class.to_s)+
           ') at line '+swarn(__LINE__.to_s)
      opne 'The original_file entry was: '+simp(original_file.to_s)
      pp error
    end
  }
  process_registered_programs
end
set_target_directory(i) click to toggle source
#

set_target_directory

#
# File lib/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 87
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/rbt/cookbooks/scan_source_archive/scan_source_archive.rb, line 94
def target_directory?
  @target_directory
end
Also aliased as: target_directory