class Cookbooks::Aliases
Constants
- NAMESPACE
#¶ ↑
NAMESPACE¶ ↑
#¶ ↑
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/cookbooks/aliases/initialize.rb, line 13 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/cookbooks/aliases/aliases.rb, line 173 def deep_show if is_included? opnn; e '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”.
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 221 def enable_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
#¶ ↑
find¶ ↑
find() will output in a verbose manner, regardless of the verbosity level.
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 136 def find(i = program?) if is_included?(i) opnn; e '`'+sfancy(i)+'` matches towards `'+sfancy(points_at?(i))+'`.' else opnn; e '`'+sfancy(i)+'` does not match to anything.' end end
#¶ ↑
internal_hash?¶ ↑
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 95 def internal_hash? @internal_hash end
#¶ ↑
keys¶ ↑
Assign the keys, then returns all keys. Will be sorted.
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 247 def keys? @internal_hash[:keys] end
#¶ ↑
n_registered_aliases?¶ ↑
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 41 def n_registered_aliases? @internal_hash[:raw_dataset].keys.size end
#¶ ↑
#obtain_raw_dataset¶ ↑
#¶ ↑
# File lib/cookbooks/aliases/dataset.rb, line 27 def obtain_dataset # ======================================================================= # # The main pointer to point at our yaml data. This is a Hash. # ======================================================================= # set_dataset(Cookbooks.cookbook_aliases?) obtain_raw_dataset # Also sync at the raw dataset. end
#¶ ↑
#obtain_raw_dataset¶ ↑
#¶ ↑
# File lib/cookbooks/aliases/dataset.rb, line 8 def obtain_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/cookbooks/aliases/dataset.rb, line 19 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/cookbooks/aliases/aliases.rb, line 121 def report_whether_the_input_is_an_alias(i = program?) if is_included?(i) opnn; e 'The program `'+sfancy(i)+'` is an alias, pointing '\ 'at the program `'+simp(points_at?)+'`.' else opnn; e 'The program `'+sfancy(i)+'` is NOT an alias.' end end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/cookbooks/aliases/reset.rb, line 10 def reset super() @be_verbose = false # By default, we will be fairly quiet. @internal_hash = {} # ======================================================================= # # 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/cookbooks/aliases/dataset.rb, line 42 def set_dataset(i = Cookbooks.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/cookbooks/aliases/aliases.rb, line 62 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. # ======================================================================= # i.delete!('-') if i.include? '-' ihash?[:search_for_this_program] = i end