Class: RBT::Cookbooks::Aliases

Inherits:
LeanPrototype show all
Defined in:
lib/rbt/aliases/aliases.rb

Overview

RBT::Cookbooks::Aliases

Constant Summary

Constants inherited from LeanPrototype

LeanPrototype::ALL_COLOUR_METHODS, LeanPrototype::ARRAY_KDE_KONSOLE_COLOURS_IN_USE, LeanPrototype::DAY_NAMES, LeanPrototype::NAMESPACE, LeanPrototype::SILENT_REDIRECTION

Instance Method Summary collapse

Methods inherited from LeanPrototype

#a_or_an?, #abbreviations?, #absolute_path, #action, #add_to_the_commandline_arguments, #all_binaries?, #all_files_from, #all_libraries?, #allowed_cookbook_entries?, #appdir_location_of?, #append_onto_the_internal_hash, #append_what_into, #archive_type_of?, #be_quiet?, #be_verbose?, #begins_with_a_comment?, #capitalize_first_alphabetical_character, #cd_to_the_log_directory, #cd_to_the_temp_directory, #change_directory, #change_permission, #cheering_person?, #chmod, #chop_off_archive, #clear_commandline_arguments, #cliner, #coloured_and_padded_e, #coloured_and_padded_esystem, #coloured_esystem, #colourize_directory_for_system_results, #colourize_this_error, #colourize_this_file_path, #colourize_this_warning, #commandline_arguments?, #commandline_arguments_without_hyphens?, #comment, #convert_dd_mm_yyyy_to_its_long_variant, #convert_env_variable, #copy_directory, #copy_files, #cpr, #create_directory, #current_hour?, #dd_mmm_yyy, #debug, #debug?, #directory_expanded_cookbooks?, #disable_colours, #display_md5sum?, #do_not_debug, #does_the_cookbook_include_this_program?, #does_this_expanded_cookbook_file_exist_for_this_program?, #does_this_file_exist?, #does_this_file_exist_and_is_it_a_file?, #e, #eblue, #ecomment, #ecrimson, #edir, #editor?, #efancy, #eimp, #enable_colours, #enable_debug, #ensure_main_encoding_for, #eparse, #esystem, #esystem_gold, #etomato, #ewarn, #exit_program, #expanded_cookbooks_directory_exists?, #extract_this_archive, #extract_to?, #file_compiled_programs?, #file_dirname_retaining_trailing_slash, #file_predefined_installation_instructions?, #file_specification_of_registered_cookbook_entries, #find_cookbook_alias_for, #find_this_yaml_file, #first_argument?, #first_non_hyphen_argument?, #get_all_directories_from, #get_all_files_from, #get_all_programs, #get_date, #get_extended_date, #get_files_and_directories_from, #go_to_base_dir, #home_dir?, #host_system?, #infer_the_namespace, #internal_hash_set_commandline_arguments, #is_an_archive?, #is_directory?, #is_file?, #is_github_url?, #is_make_available?, #is_meson_installed?, #is_on_gobolinux?, #is_on_windows?, #is_roebe?, #is_superuser?, #is_symlink?, #is_this_a_header?, #is_this_a_library?, #is_this_program_included?, #iso_encoding?, #load_dataset_from_this_expanded_cookbook, #load_yaml, #load_yaml_file_from_the_cookbook_directory_for_this_program, #log_directory?, #main_encoding?, #meson_build_file_exists?, #months?, #move_file, #n_programs_are_available?, #n_programs_available?, #namespace?, #no_directory_exists_at, #no_directory_was_found_at, #no_opn, #no_such_file_exists, #open_in_browser, #open_in_editor, #opncomment, #opne, #opnef, #opnerev, #opnerror, #opnesystem, #opnewarn, #opnfancy, #otomato, #packages_directory?, #path_to_this_expanded_cookbooks_dataset, #pkgconfig_directory?, #populate_the_internal_hash_with_default_values, #predefined_installation_instructions?, #prepend_this_commandline_argument, #program_version_of?, #project_base_directory?, #project_yaml_directory?, #query_path?, #rarrow?, #read_file, #read_file_in_default_encoding, #read_file_with_default_encoding, #readlines, #readlines_with_proper_encoding, #register_sigint, #registered_cookbook_entries?, #remove, #remove_archive_from_the_end, #remove_comments_from_each_line, #remove_directory, #remove_double_slashes, #remove_file, #remove_newlines, #remove_parens, #remove_symlink, #remove_the_first_commandline_argument, #remove_this_commandline_argument, #remove_this_entry_from_the_commandline_arguments, #remove_trailing_ANSII_escape_code, #remove_unnecessary_data_from_url, #rename, #report_pwd, #require_the_rbt_aliases, #reset_the_internal_hash, #return_all_archives_from_this_directory, #return_appdir_prefix, #return_commandline_arguments_with_leading_hyphens, #return_current_hour_minutes_second, #return_date, #return_day_of_the_month_based_on_utc, #return_full_time, #return_hours_minutes_seconds_based_on_utc, #return_location_to_this_programs_yaml_file, #return_month_based_on_this_number, #return_month_based_on_utc, #return_opnn, #return_program_name, #return_program_name_for_gobolinux_systems, #return_program_name_via_program_information, #return_pwd, #return_unicode_warning_symbol_or_empty_string, #return_utc, #return_utc_time_in_a_format_similar_to_slackware, #return_weekday_based_on_utc, #return_year_based_on_utc, #rev, #rpn, #run_simulation=, #run_simulation?, #sdir, #sdir_return_pwd, #set_be_silent, #set_be_verbose, #set_first_commandline_argument, #set_namespace, #set_use_colours, #set_use_opn, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #silently_create_this_directory_if_it_does_not_yet_exist, #simp, #source_base_directory?, #ssym, #stderr, #store_into_this_directory?, #string_right_arrow?, #swarn, #symlink, #sysbin_directory?, #sysetc_directory?, #sysinclude_directory?, #syslib_directory?, #sysshare_directory?, #system_directory?, #temp_directory?, #to_bool, #to_camelcase, #to_iso_encoding, #to_unicode, #today?, #touch, #try_to_require_beautiful_url, #try_to_require_the_environment_information_gem, #try_to_require_the_extracter_gem, #try_to_require_the_open_gem, #try_to_require_the_xorg_buffer, #try_to_require_wget, #try_to_return_a_special_compile_component, #unicode_cliner, #unicode_middle_cliner, #use_colours=, #use_colours?, #use_opn=, #use_opn?, #utf_encoding?, #verbose_truth, #word_wrap, #write_what_into, #write_what_into_via_unicode, #yes_or_no

Constructor Details

#initialize(this_program = DEFAULT_PROGRAM_ENTRY, run_already = true) ⇒ Aliases

#

initialize

The first argument, ‘this_program`, will be assigned to the instance variable @this_program, which keeps track of our original input.

#


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rbt/aliases/aliases.rb', line 101

def initialize(
    this_program = DEFAULT_PROGRAM_ENTRY,
    run_already  = true
  )
  register_sigint
  reset
  set_search_for_this_program(
    this_program
  )
  run if run_already
end

Instance Method Details

#available_programs?Boolean Also known as: available_programs, programs?, aliases?

#

avaiable_programs?

#

Returns:

  • (Boolean)


269
270
271
# File 'lib/rbt/aliases/aliases.rb', line 269

def available_programs?
  raw_aliases?.keys
end

#dataset?Boolean Also known as: dataset, data?, data

#

dataset?

#

Returns:

  • (Boolean)


188
189
190
# File 'lib/rbt/aliases/aliases.rb', line 188

def dataset?
  @internal_hash[:dataset]
end

#deep_showObject Also known as: show_all_matches

#

deep_show

This will show all matches. It is thought to be used in conjunction with a query (and obviously, the variable @is_included must be set for this to work.

#


233
234
235
236
237
238
239
240
# File 'lib/rbt/aliases/aliases.rb', line 233

def deep_show
  if is_included?
    opne "#{rev}Additionally, also showing all aliases starting "\
         "with `#{sfancy(program?)}#{rev}*`."
    all_matches = keys?.select {|key| key =~ /^#{program?}/ }
    e all_matches.sort.join(', ').split(N).map {|entry| '  '+entry }.join(N)
  end
end

#enable_aliasesObject

#

enable_aliases

This method is required so that keys such as “qt4r” also work, which is an alias of “qt4ruby” pointing towards “qt4qtruby”.

This will, however had, only be done if the variable at @internal_hash is set to true.

#


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/rbt/aliases/aliases.rb', line 284

def enable_aliases
  if @internal_hash[:use_abbreviations_for_the_aliases]
    _ = {} # This will become the new Hash.
    # ===================================================================== #
    # Iterate over the old aliases.
    # ===================================================================== #
    dataset?.each_pair {|key, value|
      _[key]   = value
      _[value] = value # Also keep itself as name.
      loop {
        # ================================================================= #
        # Get all but the last two characters repeatedly, so we chop up
        # the keys.
        # ================================================================= #
        key = key[0..-2]
        _[key] = value
        break if key.empty?
      }
    }
    set_dataset(_)
  end
end

#find(i = program?) ) ⇒ Object Also known as: show

#

find

find() will output in a verbose manner, regardless of the verbosity level.

#


217
218
219
220
221
222
223
224
# File 'lib/rbt/aliases/aliases.rb', line 217

def find(i = program?)
  if is_included?(i)
    opne rev+'`'+sfancy(i)+rev+'` matches towards `'+
         sfancy(points_at?(i))+rev+'`.'
  else
    opne "#{rev}`#{sfancy(i)}#{rev}` does not match to anything."
  end
end

#internal_hash?Boolean Also known as: ihash?

#

internal_hash?

#

Returns:

  • (Boolean)


380
381
382
# File 'lib/rbt/aliases/aliases.rb', line 380

def internal_hash?
  @internal_hash
end

#is_a_real_alias?(i = input?) ) ⇒ Boolean

#

is_a_real_alias?

This method tells us whether we have a real alias, that is originating from the initial Hash, or whether we have an alias that we deduced.

#

Returns:

  • (Boolean)


181
182
183
# File 'lib/rbt/aliases/aliases.rb', line 181

def is_a_real_alias?(i = input?)
  raw_aliases?.has_key? i
end

#is_included?(i = program_name?) ) ⇒ Boolean Also known as: is_an_alias?, includes?, found?, was_found?

#

is_included?

#

Returns:

  • (Boolean)


387
388
389
# File 'lib/rbt/aliases/aliases.rb', line 387

def is_included?(i = program_name?)
  dataset?.has_key? i
end

#keys?Boolean Also known as: keys

#

keys

Assign the keys, then returns all keys. Will be sorted.

#

Returns:

  • (Boolean)


312
313
314
# File 'lib/rbt/aliases/aliases.rb', line 312

def keys?
  @internal_hash[:keys]
end
#

menu

#


461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/rbt/aliases/aliases.rb', line 461

def menu(
    i = search_for_which_program?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ======================================================================= #
    # === ashower --show_all_abbreviations
    # ======================================================================= #
    when /^-?-?show(_|-)?abbreviations$/i, # ashower SHOW_ABBREVIATIONS
         /^-?-?show(_|-)?all(_|-)?abbreviations$/
      show_all_abbreviations
      exit
    # ======================================================================= #
    # === ashower --all
    # ======================================================================= #
    when /^-?-?all$/i # Careful - 0install will match towards this, hence the leading '^'.
      show_all_available_entries
      exit
    # ======================================================================= #
    # === ashower --show_all
    # ======================================================================= #
    when /-?-?show(_|-)?all$/i # ashower SHOW_ALL
      show_all_matches # Show all matches.
    # ======================================================================= #
    # === ashower --n_entries
    # ======================================================================= #
    when /^-?-?n(_|-)?entries$/i
      report_n_entries
      exit
    # ======================================================================= #
    # === ashower --help
    # ======================================================================= #
    when /^-?-?help$/i # <- Otherwise we would match towards "devhelp".
      show_help :then_exit
    end
  end
end

#n_registered_aliases?Boolean Also known as: n_registered_programs?, n_entries?

#

n_registered_aliases?

#

Returns:

  • (Boolean)


148
149
150
# File 'lib/rbt/aliases/aliases.rb', line 148

def n_registered_aliases?
  @internal_hash[:raw_dataset].keys.size
end

#obtain_datasetObject

#

obtain_raw_dataset

#


431
432
433
434
435
436
437
438
439
# File 'lib/rbt/aliases/aliases.rb', line 431

def obtain_dataset
  # ======================================================================= #
  # The main pointer to point at our yaml data. This is a Hash.
  # ======================================================================= #
  set_dataset(
    RBT.cookbook_aliases? # Defined in rbt/aliases/aliases.rb
  )
  obtain_raw_dataset # Also sync at the raw dataset.
end

#obtain_raw_datasetObject

#

obtain_raw_dataset

#


397
398
399
400
401
402
403
404
405
# File 'lib/rbt/aliases/aliases.rb', line 397

def obtain_raw_dataset
  # ======================================================================= #
  # === :raw_dataset
  #
  # Keep a raw dataset, as reference copy. The raw dataset is the
  # unmodified set of key-value pairs.
  # ======================================================================= #
  @internal_hash[:raw_dataset] = @internal_hash[:dataset].dup
end

#opnnObject

#

opnn

#


141
142
143
# File 'lib/rbt/aliases/aliases.rb', line 141

def opnn
  super(namespace?)
end

#points_at?(i = program_name?) ) ⇒ Boolean Also known as: real_alias, points_to?, expanded_name, replace

#

points_at?

Return the alias-pointer, without any additional checking whatsoever.

Note that [] is also available as alias.

#

Returns:

  • (Boolean)


249
250
251
# File 'lib/rbt/aliases/aliases.rb', line 249

def points_at?(i = program_name?)
  dataset?[i]
end

#raw_dataset?Boolean Also known as: raw_data?, raw_aliases?

#

raw_dataset?

#

Returns:

  • (Boolean)


410
411
412
# File 'lib/rbt/aliases/aliases.rb', line 410

def raw_dataset?
  @internal_hash[:raw_dataset]
end

#reportObject

#

report

#


504
505
506
507
508
509
510
511
# File 'lib/rbt/aliases/aliases.rb', line 504

def report
  opne 'The available aliases are:'
  opne keys?.join(', ')
  opne 'The available datasets are:'
  pp data?
  opne "The total size of all available aliases-keys is "\
       "#{keys?.size} entries."
end

#report_n_entries(i = n_entries? ) ⇒ Object

#

report_n_entries

#


340
341
342
343
344
345
346
347
# File 'lib/rbt/aliases/aliases.rb', line 340

def report_n_entries(
    i = n_entries?
  )
  e
  opne "#{rev}We have n entries (== core aliases) registered:"
  opne "  #{sfancy(i)}"
  e
end

#report_whether_the_input_is_an_alias(i = program? ) ⇒ Object

#

report_whether_the_input_is_an_alias

This method can be used to report whether the given input is an alias or whether it is not.

#


200
201
202
203
204
205
206
207
208
209
# File 'lib/rbt/aliases/aliases.rb', line 200

def report_whether_the_input_is_an_alias(
    i = program?
  )
  if is_included?(i)
    opne rev+'The program `'+sfancy(i)+rev+'` is an alias, pointing '+
         "at the program `#{simp(points_at?)}."
  else
    opne "#{rev}The program `#{sfancy(i)}#{rev}` is NOT an alias."
  end
end

#resetObject

#

reset (reset tag)

#


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rbt/aliases/aliases.rb', line 116

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  do_not_be_verbose # By default, we will be fairly quiet.
  # ======================================================================= #
  # === :use_abbreviations_for_the_aliases
  #
  # The next setting determines whether class Cookbooks::Aliases will
  # use abbreviations for its core-defined aliases. The core-defined
  # aliases are those that are written in the .yml file directly;
  # the abbreviations to these aliases, are NOT core aliases.
  #
  # By default, we will NOT use abbreviations - you have to specifically
  # enable this in your code if you want to use abbreviations.
  # ======================================================================= #
  @internal_hash[:use_abbreviations_for_the_aliases] = false
  obtain_dataset
end

#runObject

#

run

#


516
517
518
519
520
# File 'lib/rbt/aliases/aliases.rb', line 516

def run
  enable_aliases
  set_keys
  menu
end

#search_for_this_program?Boolean Also known as: search_for_which_program?, program?, program_name?, this_program?, input?

#

search_for_this_program?

#

Returns:

  • (Boolean)


156
157
158
# File 'lib/rbt/aliases/aliases.rb', line 156

def search_for_this_program?
  ihash?[:search_for_this_program]
end

#set_dataset(i = RBT.cookbook_aliases?) ⇒ Object

#

set_dataset

This sets the main dataset. If you ever need the raw dataset, make use of the method called raw_dataset?. Note that this dataset will lateron become expanded via “aliases” to this dataset.

#


422
423
424
425
426
# File 'lib/rbt/aliases/aliases.rb', line 422

def set_dataset(
    i = RBT.cookbook_aliases?
  )
  @internal_hash[:dataset] = i
end

#set_keys(i = dataset?.keys.sort) ⇒ Object

#

set_keys

This will keep track of how many keys there are in our dataset.

#


169
170
171
172
173
# File 'lib/rbt/aliases/aliases.rb', line 169

def set_keys(
    i = dataset?.keys.sort
  )
  @internal_hash[:keys] = i
end

#set_search_for_this_program(i = DEFAULT_PROGRAM_ENTRY) ⇒ Object

#

set_search_for_this_program

This setter method will search for the given program at hand.

#


354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/rbt/aliases/aliases.rb', line 354

def set_search_for_this_program(
    i = DEFAULT_PROGRAM_ENTRY
  )
  i = i.first if i.is_a? Array
  i = DEFAULT_PROGRAM_ENTRY if i.nil?
  i = i.to_s.dup # To ensure that it is never nil.
  # ======================================================================= #
  # Remove all '_' characters since as of March 2012.
  # Disabled this again in August 2018 - let's see which variant
  # will be kept in the long run.
  # ======================================================================= #
  # i.delete!('-') if i.include? '-'
  ihash?[:search_for_this_program] = i
end

#show_all_abbreviationsObject

#

show_all_abbreviations

#


372
373
374
375
# File 'lib/rbt/aliases/aliases.rb', line 372

def show_all_abbreviations
  abbreviations = dataset?
  pp abbreviations
end

#show_all_available_entriesxObject

#

show_all_available_entries

#


319
320
321
# File 'lib/rbt/aliases/aliases.rb', line 319

def show_all_available_entriesx
  pp keys?.sort
end

#show_help(shall_we_exit = false) ⇒ Object

#

show_help

This method is used to show the available help-options for this class.

#


447
448
449
450
451
452
453
454
455
456
# File 'lib/rbt/aliases/aliases.rb', line 447

def show_help(
    shall_we_exit = false
  )
  shall_we_exit = true if shall_we_exit == :then_exit
  opne 'These options exist:'
  e
  ecomment '  --n_entries # show how many cookbook entries exist'
  e
  exit if shall_we_exit
end

#show_sizeObject

#

show_size

#


261
262
263
264
# File 'lib/rbt/aliases/aliases.rb', line 261

def show_size
  opne "#{rev}We have #{sfancy(n_registered_programs?.to_s)}"\
       " #{rev}unique programs registered."
end

#translate_alias(i = program?) ) ⇒ Object Also known as: value?, [], translate, result?, result

#

translate_alias

This method will try to “translate” an alias.

#


328
329
330
331
# File 'lib/rbt/aliases/aliases.rb', line 328

def translate_alias(i = program?)
  return dataset?[i] if is_included? # Found the result here.
  return i
end