class RBT::Cookbooks::ShowDependenciesOn

Public Class Methods

new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 35
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

add(i) click to toggle source
#

add

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 67
def add(i)
  if i.include? '.'
    i = File.basename(i).gsub(File.extname(i), '')
  end
  @array_programs << i
end
fetch_all_programs_that_depend_on_the_given_input() click to toggle source
#

fetch_all_programs_that_depend_on_the_given_input

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 116
def fetch_all_programs_that_depend_on_the_given_input
  all_cookbook_files = cookbook_files?(:show_full_path)
  all_cookbook_files.each {|file|
    file = File.basename(file)
    dataset = RBT::Cookbooks::SanitizeCookbook.new(file) { :fast }
    data = dataset.dependencies_on?
    unless data.nil?
      add(file) if data.include? input? # Add it if the input is part of the dependencies.
    end
  }
end
input?() click to toggle source
#

input?

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 77
def input?
  @input
end
notify_the_user_that_this_might_take_a_while() click to toggle source
#

notify_the_user_that_this_might_take_a_while

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 106
def notify_the_user_that_this_might_take_a_while
  opne 'Scanning through the available programs next to find out'
  opne 'which programs depend on '+sfancy(input?)+  '. This may '\
       'take a while,'
  opne 'please be patient.'
end
report( i = @array_programs )
report_which_programs_depend_on_the_given_input( i = @array_programs ) click to toggle source
#

report_which_programs_depend_on_the_given_input (report tag)

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 84
def report_which_programs_depend_on_the_given_input(
    i = @array_programs
  )
  opne 'These '+sfancy(i.size.to_s)+' programs '\
       'depend on '+simp(input?.to_s)+':'
  e
  i.sort.each_with_index {|entry, index| # Sort it alphabetically here.
    index += 1
    index = index.to_s.rjust(i.size.to_s.size)
    index = slateblue(index.to_s)
    index = ('('+index.to_s+')').rjust(4)
    index.sub!(/\(/, royalblue('('))
    index.sub!(/\)/, royalblue(')'))
    entry = teal(entry)
    e "  #{index} #{entry}"
  }
  e
end
Also aliased as: report
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 47
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_programs
  # ======================================================================= #
  @array_programs = []
end
run() click to toggle source
#

run

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 131
def run
  notify_the_user_that_this_might_take_a_while
  fetch_all_programs_that_depend_on_the_given_input
  report_which_programs_depend_on_the_given_input
end
set_input(i) click to toggle source
#

set_input

#
# File lib/rbt/cookbooks/show_dependencies_on.rb, line 59
def set_input(i)
  i = i.join(' ') if i.is_a? Array
  @input = i
end