class RBT::Cookbooks::ShowDependenciesOf

Public Class Methods

new( of_this_program = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 31
def initialize(
    of_this_program = ARGV,
    run_already     = true
  )
  reset
  set_of_this_program(
    of_this_program
  )
  run if run_already
end

Public Instance Methods

gather_all_unique_dependencies_for(i) click to toggle source
#

gather_all_unique_dependencies_for

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 128
def gather_all_unique_dependencies_for(i)
  i = sanitize_this_array(i)
  @array_all_dependencies << i
  # ======================================================================= #
  # Next add more to that Array.
  # ======================================================================= #
  i.each {|entry|
    _ = RBT::Cookbooks::SanitizeCookbook.new(entry) { :fast }
    deps = _.required_deps_on?
    if deps # Must catch stray nils.
      @array_all_dependencies << sanitize_this_array(deps)
      @array_all_dependencies.flatten!
      @array_all_dependencies.uniq!
    end
  }
end
program?() click to toggle source
#

program?

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 67
def program?
  @of_this_program
end
report( i = @array_all_dependencies ) click to toggle source
#

report

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 111
def report(
    i = @array_all_dependencies
  )
  e "All gathered dependencies of `#{sfancy(program?.to_s)}` are:"
  e
  i.each_with_index {|entry, index| index += 1
    padded_index = royalblue(
      ("(#{index})").rjust(5)
    )
    e " #{padded_index} #{steelblue(entry)}"
  }
  e
end
report_these_dependencies(deps) click to toggle source
#

report_these_dependencies

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 74
def report_these_dependencies(deps)
  if deps.empty?
    opne "No dependencies have been found "\
         "for `#{sfancy(program?.to_s)}`."
  else
    opne 'The (direct) dependencies of `'+sfancy(program?.to_s)+'` are:'
    e
    deps.each_with_index {|entry, index| index += 1
      index = index.to_s.rjust(deps.size.to_s.size)
      index = slateblue(index.to_s)
      e "  (#{index.to_s}) #{steelblue(entry)}"
    }; e
  end
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 45
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_all_dependencies
  # ======================================================================= #
  @array_all_dependencies = []
end
run() click to toggle source
#

run

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 148
def run
  _ = RBT::Cookbooks::SanitizeCookbook.new(program?) { :fast }
  deps = _.required_deps_on? # This will be an array.
  report_these_dependencies(deps)
  gather_all_unique_dependencies_for(deps)
  sort_the_big_array
  report
end
sanitize_this_array(i) click to toggle source
#

sanitize_this_array

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 92
def sanitize_this_array(i)
  i.map {|entry|
    if entry.include? ' '
      entry = entry.split(' ').first.to_s.strip
    end
    entry
  }
end
set_of_this_program(of_this_program) click to toggle source
#

set_of_this_program

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 57
def set_of_this_program(of_this_program)
  if of_this_program.is_a? Array
    of_this_program = of_this_program.first
  end
  @of_this_program = of_this_program
end
sort_the_big_array() click to toggle source
#

sort_the_big_array

#
# File lib/rbt/utility_scripts/show_dependencies_of.rb, line 104
def sort_the_big_array
  @array_all_dependencies.sort!
end