class RBT::RegisteredTags

Public Class Methods

[]() click to toggle source
#

RBT::RegisteredTags[]

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

initialize

#
Calls superclass method RBT::LeanPrototype::new
# File lib/rbt/registered/registered_tags.rb, line 55
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

also_storing_into() click to toggle source
#

also_storing_into

#
# File lib/rbt/registered/registered_tags.rb, line 178
def also_storing_into
  e "#{rev}Also storing into "
end
available_cookbooks?() click to toggle source
#

available_cookbooks?

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

menu

#
reset() click to toggle source
#

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/registered/registered_tags.rb, line 68
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @hash_available_tags
  # ======================================================================= #
  @hash_available_tags = {}
end
run() click to toggle source
#

run

#
# File lib/rbt/registered/registered_tags.rb, line 192
def run
  available_cookbooks?.each {|program|
    dataset = action(:SanitizeCookbook, program) { :fast }
    tags = dataset.tags?
    if tags
      if tags.empty?
        opne "#{crimson('Notice')}#{rev}: The program `#{sfancy(program)}"\
             "#{rev}` has no registered tags."
      else # else add it to the Hash.
        @hash_available_tags[program] = tags
      end
    else
      opne "#{rev}No tags for `#{sfancy(program.to_s)}#{rev}`."
    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 "#{rev}Must be an Array, but is a "\
        "`#{sfancy(value.class.to_s)}#{rev}`."
      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/registered/registered_tags.rb, line 119
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/registered/registered_tags.rb, line 102
def show_help(
    shall_we_exit_afterwards = false
  )
  case shall_we_exit_afterwards
  when :then_exit
    shall_we_exit_afterwards = true
  end
  opne 'This class will simply register all available tags into the file'
  opne "  #{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/registered/registered_tags.rb, line 143
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? _
  tags = tags?
  if tags
    File.open(_,'w+') { |file|
      YAML.dump(tags, file)
    }
  end
  # ======================================================================= #
  # Also store in the right file on my home system.
  #
  #   cat $RSRC/rbt/lib/rbt/yaml/registered_tags.yml
  #
  # ======================================================================= #
  if is_on_roebe?
    _ = RUBY_SRC_DIR_AT_HOME+'rbt/lib/rbt/yaml/'\
        'registered_tags/registered_tags.yml'
    File.delete(_) if File.exist? _
    e '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/registered/registered_tags.rb, line 134
def store_where?
  RBT.file_registered_tags?
end
tags?() click to toggle source
#

tags?

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