class RBT::Cookbooks::Aliases
Public Class Methods
#¶ ↑
initialize¶ ↑
The first argument, ‘this_program`, will be assigned to the instance variable @this_program, which keeps track of our original input.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 103 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
Public Instance Methods
#¶ ↑
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.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 232 def deep_show if is_included? opne "Additionally, also showing all aliases starting "\ "with `#{sfancy(program?)}*`." all_matches = keys?.select {|key| key =~ /^#{program?}/ } e all_matches.sort.join(', ').split(N).map {|entry| ' '+entry }.join(N) end end
#¶ ↑
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.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 283 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¶ ↑
find() will output in a verbose manner, regardless of the verbosity level.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 217 def find(i = program?) if is_included?(i) opne '`'+sfancy(i)+'` matches towards `'+sfancy(points_at?(i))+'`.' else opne '`'+sfancy(i)+'` does not match to anything.' end end
#¶ ↑
internal_hash?¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 379 def internal_hash? @internal_hash end
#¶ ↑
keys¶ ↑
Assign the keys, then returns all keys. Will be sorted.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 311 def keys? @internal_hash[:keys] end
#¶ ↑
n_registered_aliases?¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 150 def n_registered_aliases? @internal_hash[:raw_dataset].keys.size end
#¶ ↑
obtain_raw_dataset
¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 430 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_dataset
¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 396 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
#¶ ↑
raw_dataset?¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 409 def raw_dataset? @internal_hash[:raw_dataset] end
#¶ ↑
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.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 202 def report_whether_the_input_is_an_alias(i = program?) if is_included?(i) opne 'The program `'+sfancy(i)+'` is an alias, pointing '\ 'at the program `'+simp(points_at?)+'`.' else opne 'The program `'+sfancy(i)+'` is NOT an alias.' end end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 118 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
#¶ ↑
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.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 421 def set_dataset( i = RBT.cookbook_aliases? ) @internal_hash[:dataset] = i end
#¶ ↑
set_search_for_this_program
¶ ↑
This setter method will search for the given program at hand.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 353 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_help
¶ ↑
This method is used to show the available help-options for this class.
#¶ ↑
# File lib/rbt/aliases/aliases.rb, line 446 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