class Cookbooks::Aliases

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( this_program = DEFAULT_PROGRAM_ENTRY, run_already = true ) click to toggle source
#

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

[](i = program_name?)
Alias for: points_at?
aliases?()
Alias for: available_programs?
available_programs()
Alias for: available_programs?
available_programs?() click to toggle source
#

avaiable_programs?

#
# File lib/cookbooks/aliases/aliases.rb, line 209
def available_programs?
  raw_aliases?.keys
end
data()
Alias for: dataset?
data?()
Alias for: dataset?
dataset()
Alias for: dataset?
dataset?() click to toggle source
#

dataset?

#
# File lib/cookbooks/aliases/aliases.rb, line 102
def dataset?
  @internal_hash[:dataset]
end
Also aliased as: dataset, data?, data
deep_show() click to toggle source
#

#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
Also aliased as: show_all_matches
enable_aliases() click to toggle source
#

#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
expanded_name(i = program_name?)
Alias for: points_at?
find(i = program?) click to toggle source
#

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
Also aliased as: show
found?(i = program_name?)
Alias for: is_included?
ihash?()
Alias for: internal_hash?
includes?(i = program_name?)
Alias for: is_included?
input?()
internal_hash?() click to toggle source
#

internal_hash?

#
# File lib/cookbooks/aliases/aliases.rb, line 95
def internal_hash?
  @internal_hash
end
Also aliased as: ihash?
is_a_real_alias?(i = input?) click to toggle source
#

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.

#
# File lib/cookbooks/aliases/aliases.rb, line 88
def is_a_real_alias?(i = input?)
  raw_aliases?.has_key? i
end
is_an_alias?(i = program_name?)
Alias for: is_included?
is_included?(i = program_name?) click to toggle source
#

is_included?

#
# File lib/cookbooks/aliases/aliases.rb, line 147
def is_included?(i = program_name?)
  dataset?.has_key? i
end
Also aliased as: is_an_alias?, includes?, found?, was_found?
keys()
Alias for: keys?
keys?() click to toggle source
#

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
Also aliased as: keys
menu(i = search_for_which_program?) click to toggle source
#

menu

#
n_entries?()
n_registered_aliases?() click to toggle source
#

n_registered_aliases?

#
# File lib/cookbooks/aliases/aliases.rb, line 41
def n_registered_aliases?
  @internal_hash[:raw_dataset].keys.size
end
n_registered_programs?()
obtain_dataset() click to toggle source
#

#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() click to toggle source
#

#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
opnn() click to toggle source
#

opnn

#
Calls superclass method
# File lib/cookbooks/aliases/aliases.rb, line 111
def opnn
  super(NAMESPACE)
end
points_at?(i = program_name?) click to toggle source
#

points_at?

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

Note that [] is also available as alias.

#
# File lib/cookbooks/aliases/aliases.rb, line 189
def points_at?(i = program_name?)
  dataset?[i]
end
points_to?(i = program_name?)
Alias for: points_at?
program?()
program_name?()
programs?()
Alias for: available_programs?
raw_aliases?()
Alias for: raw_dataset?
raw_data?()
Alias for: raw_dataset?
raw_dataset?() click to toggle source
#

raw_dataset?

#
# File lib/cookbooks/aliases/dataset.rb, line 19
def raw_dataset?
  @internal_hash[:raw_dataset]
end
Also aliased as: raw_data?, raw_aliases?
real_alias(i = program_name?)
Alias for: points_at?
replace(i = program_name?)
Alias for: points_at?
report() click to toggle source
#

report

#
# File lib/cookbooks/aliases/aliases.rb, line 157
def report
  opnn; e 'The available aliases are:'
  opnn; e keys?.join(', ')
  opnn; e 'The available datasets are:'
  pp data?
  opnn; e 'The total size of all available aliases-keys is '+
           keys?.size.to_s+' entries.'
end
report_n_entries(i = n_entries?) click to toggle source
#

#report_n_entries

#
# File lib/cookbooks/aliases/aliases.rb, line 275
def report_n_entries(i = n_entries?)
  e
  opnn; e 'We have n entries (== core aliases) registered:'
  opnn; e "  #{sfancy(i)}"
  e
end
report_whether_the_input_is_an_alias(i = program?) click to toggle source
#

#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() click to toggle source
#

reset (reset tag)

#
Calls superclass method
# 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
result(i = program?)
Alias for: translate_alias
result?(i = program?)
Alias for: translate_alias
run() click to toggle source
#

run

#
# File lib/cookbooks/aliases/run.rb, line 10
def run
  enable_aliases
  set_keys
  menu
end
search_for_this_program?() click to toggle source
#

search_for_this_program?

#
# File lib/cookbooks/aliases/aliases.rb, line 49
def search_for_this_program?
  ihash?[:search_for_this_program]
end
search_for_which_program?()
set_dataset(i = Cookbooks.cookbook_aliases?) click to toggle source
#

#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_keys(i = dataset?.keys.sort) click to toggle source
#

#set_keys

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

#
# File lib/cookbooks/aliases/aliases.rb, line 78
def set_keys(i = dataset?.keys.sort)
  @internal_hash[:keys] = i
end
set_search_for_this_program(i = DEFAULT_PROGRAM_ENTRY) click to toggle source
#

#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
show(i = program?)
Alias for: find
show_all_abbreviations() click to toggle source
#

#show_all_abbreviations

#
# File lib/cookbooks/aliases/aliases.rb, line 285
def show_all_abbreviations
  abbreviations = dataset?
  pp abbreviations
end
show_all_available_entriesx() click to toggle source
#

show_all_available_entries

#
# File lib/cookbooks/aliases/aliases.rb, line 254
def show_all_available_entriesx
  pp keys?.sort
end
show_all_matches()
Alias for: deep_show
show_help( shall_we_exit = false ) click to toggle source
#

#show_help

#
# File lib/cookbooks/aliases/help.rb, line 8
def show_help(
    shall_we_exit = false
  )
  shall_we_exit = true if shall_we_exit == :then_exit
  opnn; e 'These options exist:'
  opnn; ecomment '  --n_entries # show how many cookbook entries exist'
  exit if shall_we_exit
end
show_size() click to toggle source
#

#show_size

#
# File lib/cookbooks/aliases/aliases.rb, line 201
def show_size
  opnn; e 'We have '+sfancy(n_registered_programs?.to_s)+
          ' unique programs registered.'
end
this_program?()
translate(i = program?)
Alias for: translate_alias
translate_alias(i = program?) click to toggle source
#

#translate_alias

This method will try to “translate” an alias.

#
# File lib/cookbooks/aliases/aliases.rb, line 263
def translate_alias(i = program?)
  return dataset?[i] if is_included? # Found the result here.
  return i
end
Also aliased as: translate, value?, [], result?, result
value?(i = program_name?)
Alias for: points_at?
was_found?(i = program_name?)
Alias for: is_included?