class RBT::RegisteredTags

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

[]() click to toggle source
#

RBT::RegisteredTags[]

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 231
def self.[]
  self.new
end
new( optional_commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method RBT::Base::new
# File lib/rbt/utility_scripts/registered_tags.rb, line 67
def initialize(
    optional_commandline_arguments = ARGV,
    run_already                    = true
  )
  super()
  reset
  menu(optional_commandline_arguments) if optional_commandline_arguments
  run if run_already
end

Public Instance Methods

available_cookbooks?() click to toggle source
#

available_cookbooks?

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 134
def available_cookbooks?
  RBT.available_programs?
end
menu(i) click to toggle source
#

menu

#
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/registered_tags.rb, line 115
def reset
  super()
  @hash_available_tags = {}
  @namespace = NAMESPACE
end
run() click to toggle source
#

run

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 186
def run
  available_cookbooks?.each {|program|
    # opn; e 'Now working on `'+sfancy(program)+'`.'
    # ^^^ Too spammy as output.
    dataset = RBT::Cookbooks::Cookbook.new(program) { :bypass_menu }
    tags = dataset.tags?
    if tags
      if tags.empty?
        opnn; e "#{crimson('Notice')}: The program `#{sfancy(program)}` has "\
                "no registered tags."
      else # else add it to the Hash.
        @hash_available_tags[program] = tags
      end
    else
      opnn; e 'No tags for `'+sfancy(program.to_s)+'`.'
    end
  }
  # ======================================================================= #
  # Note that at this point, the hash is not correct yet.
  # It will have entries such as:
  #   "thor"=>["ruby"]
  # but it should be the other way around.
  # ======================================================================= #
  inverted_hash = {}
  tags?.each_pair {|name_of_the_program, value|
    unless value.is_a? Array
      e 'Must be an Array, but is a `'+sfancy(value.class.to_s)+'`.'
      e 'This is not allowed - correct the entry please.'
      e 'Exiting now as a consequence.'
      exit
    end
    value.each {|program_type|
      unless inverted_hash.has_key? program_type
        inverted_hash[program_type] = []
      end
      inverted_hash[program_type] << name_of_the_program 
    }
  }
  set_hash(inverted_hash)
  store_main_hash
end
set_hash(i) click to toggle source
#

set_hash

Use this method to set to the main hash.

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 126
def set_hash(i)
  raise 'Must be a hash.' unless i.is_a? Hash
  @hash_available_tags = i
end
show_help( shall_we_exit_afterwards = false ) click to toggle source
#

show_help

To invoke this method from the commandline, do:

registered_tags --help
#
# File lib/rbt/utility_scripts/registered_tags.rb, line 100
def show_help(
    shall_we_exit_afterwards = false
  )
  case shall_we_exit_afterwards
  when :then_exit
    shall_we_exit_afterwards = true
  end
  opnn; e 'This class will simply register all available tags into the file'
  opnn; e "  #{sfile(store_where?)}"
  exit if shall_we_exit_afterwards
end
store_main_hash() click to toggle source
#

store_main_hash

Write the hash into a file.

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 150
def store_main_hash
  _ = store_where?
  e sfancy('Storing yaml dataset in ')
  e '  '+sfile(_)
  # ======================================================================= #
  # Purge the old file first before adding new data to it.
  # ======================================================================= #
  remove_file(_) if File.exist? _
  File.open(_,'w+') { |file|
    YAML.dump(tags?, file)
  }
  # ======================================================================= #
  # Also store in the right file on my home system.
  #   cat $RSRC/cookbooks/lib/cookbooks/yaml/registered_tags.yml
  # ======================================================================= #
  if is_on_roebe?
    _ = RUBY_SRC_DIR_AT_HOME+'rbt/lib/rbt/yaml/registered_tags.yml'
    File.delete(_) if File.exist? _
    e sfancy('Also storing into ')
    e '  '+sfile(_)
    File.open(_,'w+') { |file|
      YAML.dump(tags?, file)
    }
  end
end
store_where?() click to toggle source
#

store_where?

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 141
def store_where?
  LOCATION_REGISTERED_TAGS
end
tags?() click to toggle source
#

tags?

#
# File lib/rbt/utility_scripts/registered_tags.rb, line 179
def tags?
  @hash_available_tags
end