Class: Rcfiles::DirectoryAliases
- Inherits:
-
Object
- Object
- Rcfiles::DirectoryAliases
- Defined in:
- lib/rcfiles/directory_aliases/directory_aliases.rb,
lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb,
lib/rcfiles/directory_aliases/yaml_file_used_by_class_directory_aliases.rb
Overview
Rcfiles::DirectoryAliases
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect- NAME_OF_FILE =
#
Rcfiles::DirectoryAliases::NAME_OF_FILE
#
'directory_aliases.rb'- SHALL_WE_SHOW_EXCEPTIONS =
#
Rcfiles::DirectoryAliases::SHALL_WE_SHOW_EXCEPTIONS
#
false- DEFAULT_RUN_MODE =
#
Rcfiles::DirectoryAliases::DEFAULT_RUN_MODE
#
true
Class Method Summary collapse
-
.[](i = '') ⇒ Object
# === Rcfiles::DirectoryAliases[].
-
.clear ⇒ Object
# === Rcfiles::DirectoryAliases.clear.
-
.e(i = '') ⇒ Object
# === Rcfiles::DirectoryAliases.e ========================================================================= #.
-
.initialize_main_hash ⇒ Object
# === Rcfiles::DirectoryAliases.initialize_main_hash ========================================================================= #.
-
.is_included?(i) ⇒ Boolean
# === Rcfiles::DirectoryAliases.is_included?.
-
.load_dataset_from_main_file(i = yaml_file? ) ⇒ Object
# === Rcfiles::DirectoryAliases.load_dataset_from_main_file.
-
.n_entries? ⇒ Boolean
# === Rcfiles::DirectoryAliases.n_entries?.
-
.points_at?(i) ⇒ Boolean
# === Rcfiles::DirectoryAliases.points_at? ========================================================================= #.
-
.register_sigint ⇒ Object
# === Rcfiles::DirectoryAliases.register_sigint ========================================================================= #.
-
.save_into_ruby_file(store_into_this_file = '/Depot/j/expand_cd_aliases_hash.rb', name_of_the_main_hash = 'EXPAND_CD_ALIASES_HASH') ⇒ Object
# === Rcfiles::DirectoryAliases.save_into_ruby_file.
-
.set_toplevel_stored_dataset(i = {}) ⇒ Object
# === Rcfiles::DirectoryAliases.set_toplevel_stored_dataset (set_cd_aliases tag).
-
.set_yaml_file_used_by_class_directory_aliases(i = :default) ⇒ Object
# === Rcfiles::DirectoryAliases.set_yaml_file_used_by_class_directory_aliases.
-
.toplevel_stored_dataset? ⇒ Boolean
# === Rcfiles::DirectoryAliases.toplevel_stored_dataset?.
-
.yaml_file? ⇒ Boolean
# === Rcfiles::DirectoryAliases.yaml_file?.
Instance Method Summary collapse
-
#[](i) ⇒ Object
# === [] ========================================================================= #.
-
#be_silent ⇒ Object
(also: #be_quiet)
# === be_silent ========================================================================= #.
-
#be_verbose ⇒ Object
# === be_verbose ========================================================================= #.
-
#be_verbose? ⇒ Boolean
# === be_verbose? ========================================================================= #.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#dataset? ⇒ Boolean
(also: #hash?, #hash, #cd_aliases?)
# === dataset?.
-
#do_sanitize_the_loaded_dataset(hash = hash?, , use_this_yaml_file = ::Rcfiles.project_base_directory?+ 'yaml/global_variables/'\ 'global_variables_extracted_from_the_file_cd_aliases.yml') ⇒ Object
(also: #sanitize_hash, #sanitize_the_hash, #sanitize_cd_aliases)
# === do_sanitize_the_loaded_dataset (sanitize tag).
-
#file? ⇒ Boolean
# === file?.
-
#first_argument? ⇒ Boolean
(also: #first?, #seek_this_key?, #seek_which_key?)
# === first_argument? ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, run_already = DEFAULT_RUN_MODE) ⇒ DirectoryAliases
constructor
# === initialize.
-
#is_this_key_included?(key = first_argument? ) ⇒ Boolean
(also: #included?, #is_included?, #is_this_input_a_cd_alias?, #is_this_key_registered?, #is_this_alias_included?, #has_key?)
# === is_this_key_included?.
-
#keys? ⇒ Boolean
# === keys? ========================================================================= #.
-
#load_the_dataset_from_the_file_cd_aliases(file_cd_aliases = ::Rcfiles::DirectoryAliases.yaml_file?) ⇒ Object
# === load_the_dataset_from_the_file_cd_aliases.
-
#n_entries? ⇒ Boolean
# === n_entries? ========================================================================= #.
-
#opnn ⇒ Object
(also: #opn)
# === opnn ========================================================================= #.
-
#rds(i) ⇒ Object
# === rds ========================================================================= #.
-
#replacement_or_original_input?(_ = first_argument? ) ⇒ Boolean
(also: #corresponds_to, #corresponds_to?, #find_this_cd_alias, #find_this_sanitized_cd_alias, #find, #points_at, #points_at?, #result?, #convert, #_)
# === replacement_or_original_input? ========================================================================= #.
-
#report_errors? ⇒ Boolean
# === report_errors? ========================================================================= #.
-
#report_to_user ⇒ Object
# === report_to_user.
-
#report_version ⇒ Object
# === report_version ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#set_report_errors(i) ⇒ Object
# === set_report_errors ========================================================================= #.
-
#show_exceptions? ⇒ Boolean
# === show_exceptions? ========================================================================= #.
-
#size? ⇒ Boolean
(also: #keys, #size)
# === size?.
-
#test(i = seek_this_key? ) ⇒ Object
# === test ========================================================================= #.
-
#translate_key_into_value(key) ⇒ Object
# === translate_key_into_value.
-
#verbose_points_to?(i = seek_which_key?) ) ⇒ Boolean
# === verbose_points_to? ========================================================================= #.
-
#version? ⇒ Boolean
# === version?.
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = DEFAULT_RUN_MODE) ⇒ DirectoryAliases
#
initialize
The first argument is typically the key that is sought. It is optional, though, as the method .find() or .points_at?() can be used with an argument at any moment in time. That way a cd-alias can be used to query the dataset.
#
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 83 def initialize( commandline_arguments = ARGV, run_already = DEFAULT_RUN_MODE ) reset set_commandline_arguments( commandline_arguments ) # ======================================================================= # # === Handle blocks given to this class next # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :run # ===================================================================== # when :run run_already = true end end case run_already # ======================================================================= # # === :be_silent # ======================================================================= # when :be_silent be_silent run_already = DEFAULT_RUN_MODE # ======================================================================= # # === :do_not_report_errors # ======================================================================= # when :do_not_report_errors set_report_errors(false) run_already = DEFAULT_RUN_MODE end run if run_already end |
Class Method Details
.[](i = '') ⇒ Object
#
Rcfiles::DirectoryAliases[]
This must return a String - either the original input, or the replacement.
Usage example:
Rcfiles::DirectoryAliases['pwdj'] # => '/Depot/j/'
#
568 569 570 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 568 def self.[](i = '') new(i).replacement_or_original_input? end |
.clear ⇒ Object
#
Rcfiles::DirectoryAliases.clear
Reset the main Hash again.
#
70 71 72 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 70 def self.clear @toplevel_stored_dataset.clear end |
.e(i = '') ⇒ Object
#
Rcfiles::DirectoryAliases.e
#
553 554 555 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 553 def self.e(i = '') ::Rcfiles.e(i) end |
.initialize_main_hash ⇒ Object
#
Rcfiles::DirectoryAliases.initialize_main_hash
#
101 102 103 104 105 106 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 101 def self.initialize_main_hash clear # First empty the old dataset, should it be non-empty. if toplevel_dataset?.empty? load_dataset_from_main_file end end |
.is_included?(i) ⇒ Boolean
#
Rcfiles::DirectoryAliases.is_included?
Note that this instantiates a new DirectoryAliases object, so it is more expensive than instantiating on your own and then simply using .is_included? on that object. The reason why this method still exists, then, is mostly because it is convenient to NOT have to instantiate something specifically, as that normally takes two lines of code.
#
534 535 536 537 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 534 def self.is_included?(i) _ = new(i) return _.is_included?(i) end |
.load_dataset_from_main_file(i = yaml_file? ) ⇒ Object
#
Rcfiles::DirectoryAliases.load_dataset_from_main_file
Load up the dataset next
This determines the main cd-aliases file.
#
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 81 def self.load_dataset_from_main_file( i = yaml_file? ) if File.exist? i dataset = YAML.load_file(i) # This may be UTF-8 encoding. # ===================================================================== # # Assign the cd-aliases via a toplevel method next: # ===================================================================== # set_toplevel_stored_dataset(dataset) else # Else use an empty dataset instead. if is_on_roebe? ::Rcfiles.no_file_exists_at(i) end set_toplevel_stored_dataset({}) end end |
.n_entries? ⇒ Boolean
#
Rcfiles::DirectoryAliases.n_entries?
How many entries can be found in class DirectoryAliases is answered by this toplevel method.
#
49 50 51 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 49 def self.n_entries? toplevel_stored_dataset?.keys.size end |
.points_at?(i) ⇒ Boolean
#
Rcfiles::DirectoryAliases.points_at?
#
545 546 547 548 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 545 def self.points_at?(i) _ = new(i) return _.points_at? end |
.register_sigint ⇒ Object
#
Rcfiles::DirectoryAliases.register_sigint
#
117 118 119 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 117 def self.register_sigint Signal.trap('SIGINT') { exit } end |
.save_into_ruby_file(store_into_this_file = '/Depot/j/expand_cd_aliases_hash.rb', name_of_the_main_hash = 'EXPAND_CD_ALIASES_HASH') ⇒ Object
#
Rcfiles::DirectoryAliases.save_into_ruby_file
This method will store the hash in a CONSTANT, into a file (normally a .rb file).
The first argument to this method denotes where to store this file, so you have the possibility to save into some special location instead.
The name of the hash is provided via the the second argument to this method.
#
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 136 def self.save_into_ruby_file( store_into_this_file = '/Depot/j/expand_cd_aliases_hash.rb', name_of_the_main_hash = 'EXPAND_CD_ALIASES_HASH' ) _ = ::Rcfiles::DirectoryAliases.new dataset = _.cd_aliases? # ======================================================================= # # First add the header: # ======================================================================= # what = '#!/usr/bin/ruby -w # Encoding: UTF-8 # frozen_string_literal: true # =========================================================================== # '.dup what << "#{name_of_the_main_hash} = {\n" what = ::Rcfiles.ensure_main_encoding(what) dataset.each_pair {|key, value| key = key.to_s unless key.is_a? String value = ConvertGlobalEnv.convert(value) key = ::Rcfiles.ensure_main_encoding(key) value = ::Rcfiles.ensure_main_encoding(value) what << " \"#{key}\": \"#{value}\",\n" } what << "}\n" into = store_into_this_file if block_given? yielded = yield case yielded when :be_verbose puts 'Storing into the file `'+into+'`.' end end ::Rcfiles.write_what_into(what, into) end |
.set_toplevel_stored_dataset(i = {}) ⇒ Object
#
Rcfiles::DirectoryAliases.set_toplevel_stored_dataset (set_cd_aliases tag)
The @toplevel_stored_dataset should always be a Hash. This is an explicit setter here, though, so the user could always assign a non-Hash. No error will be raised in this case.
#
60 61 62 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 60 def self.set_toplevel_stored_dataset(i = {}) @toplevel_stored_dataset = i end |
.set_yaml_file_used_by_class_directory_aliases(i = :default) ⇒ Object
#
Rcfiles::DirectoryAliases.set_yaml_file_used_by_class_directory_aliases
The user can modify which yaml file is to be used, via this method call.
#
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rcfiles/directory_aliases/yaml_file_used_by_class_directory_aliases.rb', line 31 def self.set_yaml_file_used_by_class_directory_aliases( i = :default ) case i # ======================================================================= # # === :default # ======================================================================= # when :default, :default_yaml_file i = ::Rcfiles.file_cd_aliases end @yaml_file_used_by_class_directory_aliases = i end |
.toplevel_stored_dataset? ⇒ Boolean
#
Rcfiles::DirectoryAliases.toplevel_stored_dataset?
Main getter over the cd-aliases. This will be our main datastructure.
#
38 39 40 |
# File 'lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb', line 38 def self.toplevel_stored_dataset? @toplevel_stored_dataset end |
.yaml_file? ⇒ Boolean
#
Rcfiles::DirectoryAliases.yaml_file?
On my home system this defaults to:
/usr/lib/ruby/site_ruby/3.1.0/rcfiles/yaml/cd_aliases.yml
#
59 60 61 |
# File 'lib/rcfiles/directory_aliases/yaml_file_used_by_class_directory_aliases.rb', line 59 def self.yaml_file? @yaml_file_used_by_class_directory_aliases end |
Instance Method Details
#[](i) ⇒ Object
#
[]
#
520 521 522 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 520 def [](i) replacement_or_original_input?(i) end |
#be_silent ⇒ Object Also known as: be_quiet
#
be_silent
#
176 177 178 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 176 def be_silent @internal_hash[:be_verbose] = false end |
#be_verbose ⇒ Object
#
be_verbose
#
169 170 171 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 169 def be_verbose @internal_hash[:be_verbose] = true end |
#be_verbose? ⇒ Boolean
#
be_verbose?
#
183 184 185 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 183 def be_verbose? @internal_hash[:be_verbose] end |
#commandline_arguments? ⇒ Boolean
#
commandline_arguments?
#
210 211 212 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 210 def commandline_arguments? @commandline_arguments end |
#dataset? ⇒ Boolean Also known as: hash?, hash, cd_aliases?
#
dataset?
This is the query-method to access the main dataset of this class, which is a Hash.
#
193 194 195 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 193 def dataset? @internal_hash[:dataset] end |
#do_sanitize_the_loaded_dataset(hash = hash?, , use_this_yaml_file = ::Rcfiles.project_base_directory?+ 'yaml/global_variables/'\ 'global_variables_extracted_from_the_file_cd_aliases.yml') ⇒ Object Also known as: sanitize_hash, sanitize_the_hash, sanitize_cd_aliases
#
do_sanitize_the_loaded_dataset (sanitize tag)
This method will sanitize the dataset at hand.
All changes will be copied back onto the main hash, as-is - thus we lose the original data.
#
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 349 def do_sanitize_the_loaded_dataset( hash = hash?, # ===================================================================== # # Use a yaml-file containing the correct variables next: # ===================================================================== # use_this_yaml_file = ::Rcfiles.project_base_directory?+ 'yaml/global_variables/'\ 'global_variables_extracted_from_the_file_cd_aliases.yml' ) dataset_from_the_global_variables = YAML.load_file( use_this_yaml_file ) _ = {} hash.each {|key, value| # ===================================================================== # # Next, work on all value-entries that include a '$' character. This # will work on Linux, but on Windows this may not work, so we may # have to use another solution for windows specifically. However # had, we actually do not need to use ConvertGlobalEnv here, # as the autogenerated .yml file already contains the sanitized # dataset. The line has been commented out in May 2022. # # Examples for a key and value pair may be the following: # # 'to_valheru' => 'cd $VALHERU' # 'pwdshell' => 'cd $LINUX/SHELL/ # # We need to map it towards e. g.: # # ROEBE_SRC: '/home/x/programming/ruby/src/roebe/lib/roebe' # LINUX: '/home/x/programming/ruby/src/roebe/lib/roebe/www/linux' # UNI_WIEN: '/home/x/studium/UNI_WIEN' # # ===================================================================== # if value.include? '$' value = value.dup # Work on a copy past this point. value.gsub!(/cd /,'') if value.include? 'cd ' value.gsub!(/ ll/,'') if value.include? ' ll' value.gsub!(/ ls/,'') if value.include? ' ls' value.gsub!(/> \/dev\/null/,'') if value.include? '> /dev/null' value.gsub!(/2>&1/,'') if value.include? '2>&1' # =================================================================== # # The next line has been commented out on 03.05.2022: # # value = ConvertGlobalEnv.convert(value, report_errors?) # # =================================================================== # shortened_value = value.delete_prefix('cd ').dup # Now it is e. g. '$LINUX/SHELL/'. # =================================================================== # # In the past, until May 2014, we chopped off trailing occurences # of 'pwd', but I decided that this is no longer wanted. Certain # aliases such as "pwdusb4" would misfunction as a result of # the following .gsub: # # value.gsub!(/pwd$/,'') if value.include? 'pwd' # # =================================================================== # # =================================================================== # # As of May 2014, we no longer get rid of ; characters. # # value.gsub!(/;/,'') if value.include? ';' # # =================================================================== # if value and value.include?('/') # In this case it is more complicated. shortened_value = value.scan(/\$(\w+)\//).flatten.first.to_s # See: https://rubular.com/r/L2rAbtKVnnmBfd value.sub!(/\$#{shortened_value}/, dataset_from_the_global_variables[shortened_value].to_s) else # else no modification is necessary. replace_via = dataset_from_the_global_variables[shortened_value.delete('$')].to_s value.gsub!(/#{Regexp.quote(value)}/, replace_via) end end if hash.has_key?(value) value = hash[value] end value = rds(value) if value.include? '//' _[key] = value.strip # We don't need trailing empty characters. } @internal_hash[:dataset] = _ end |
#file? ⇒ Boolean
#
file?
Delegate to the main yaml file in use.
#
321 322 323 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 321 def file? ::Rcfiles::DirectoryAliases.yaml_file? end |
#first_argument? ⇒ Boolean Also known as: first?, seek_this_key?, seek_which_key?
#
first_argument?
#
217 218 219 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 217 def first_argument? @commandline_arguments.first end |
#is_this_key_included?(key = first_argument? ) ⇒ Boolean Also known as: included?, is_included?, is_this_input_a_cd_alias?, is_this_key_registered?, is_this_alias_included?, has_key?
#
is_this_key_included?
This method can be used to query whether our expanded directory-aliases contains the given key (first input argument to this method) or whether it does not.
#
304 305 306 307 308 309 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 304 def is_this_key_included?( key = first_argument? ) key = key.to_s unless key.is_a?(String) dataset?.has_key?(key) end |
#keys? ⇒ Boolean
#
keys?
#
283 284 285 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 283 def keys? dataset?.keys end |
#load_the_dataset_from_the_file_cd_aliases(file_cd_aliases = ::Rcfiles::DirectoryAliases.yaml_file?) ⇒ Object
#
load_the_dataset_from_the_file_cd_aliases
An alternative argument to this method would be ::Rcfiles.file_cd_aliases?.
#
446 447 448 449 450 451 452 453 454 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 446 def load_the_dataset_from_the_file_cd_aliases( file_cd_aliases = ::Rcfiles::DirectoryAliases.yaml_file? ) if File.exist? file_cd_aliases @internal_hash[:dataset] = YAML.load_file(file_cd_aliases) end end |
#n_entries? ⇒ Boolean
#
n_entries?
#
481 482 483 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 481 def n_entries? dataset?.size end |
#opnn ⇒ Object Also known as: opn
#
opnn
#
233 234 235 236 237 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 233 def opnn if Object.const_defined? :Opn Opn.opn(namespace: NAMESPACE) end end |
#rds(i) ⇒ Object
#
rds
#
266 267 268 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 266 def rds(i) i.squeeze('/') end |
#replacement_or_original_input?(_ = first_argument? ) ⇒ Boolean Also known as: corresponds_to, corresponds_to?, find_this_cd_alias, find_this_sanitized_cd_alias, find, points_at, points_at?, result?, convert, _
#
replacement_or_original_input?
#
459 460 461 462 463 464 465 466 467 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 459 def replacement_or_original_input?( _ = first_argument? ) if is_this_key_included?(_) translate_key_into_value(_) else return _ end end |
#report_errors? ⇒ Boolean
#
report_errors?
#
242 243 244 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 242 def report_errors? @internal_hash[:report_errors] end |
#report_to_user ⇒ Object
#
report_to_user
This is a “poor man’s” debug variant.
#
436 437 438 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 436 def report_to_user pp hash? end |
#report_version ⇒ Object
#
report_version
#
226 227 228 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 226 def report_version e "The version is: #{sfancy(version?)}" end |
#reset ⇒ Object
#
reset (reset tag)
#
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 124 def reset # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE # ======================================================================= # # === @internal_hash # ======================================================================= # @internal_hash = {} # ======================================================================= # # === :be_verbose # ======================================================================= # @internal_hash[:be_verbose] = true # ======================================================================= # # === :report_errors # # The next variable determines whether we will report errors or # whether we will not. By default this class will report errors. # # An example error may be Encoding::InvalidByteSequenceError being # raised due to the .yml file being incorrect. In my own yaml files # this error no longer happens, so the class no longer has to handle # this - but in the event that we may re-enable this feature one # day, for other users, I considered it useful in May 2022 to # still retain the :report_errors flag. # # The old code looked something like this: # # rescue Encoding::InvalidByteSequenceError => error # if be_verbose? and show_exceptions? and report_errors? # opnn; e "#{NAME_OF_FILE}: An exception/error happened for → #{simp(key.to_s)}" # opnn; e 'We will now feedback this error:' # pp error # end # end # # ======================================================================= # @internal_hash[:report_errors] = true be_quiet # Do not be too noisy by default. load_the_dataset_from_the_file_cd_aliases end |
#run ⇒ Object
#
run (run tag)
#
502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 502 def run # ======================================================================= # # We will do several clean-ups. This is extremely hackish, but also # very simple and it kind of works. We got rid of all the $ values. # How often to call it? Well, it seems 4x is more than enough; # perhaps we can reduce it even more, but for now this is the way # it is. # ======================================================================= # do_sanitize_the_loaded_dataset do_sanitize_the_loaded_dataset do_sanitize_the_loaded_dataset do_sanitize_the_loaded_dataset # do_sanitize_the_loaded_dataset end |
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
202 203 204 205 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 202 def set_commandline_arguments(i = '') i = [i].flatten.compact @commandline_arguments = i end |
#set_report_errors(i) ⇒ Object
#
set_report_errors
#
249 250 251 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 249 def set_report_errors(i) @internal_hash[:report_errors] = i end |
#show_exceptions? ⇒ Boolean
#
show_exceptions?
#
337 338 339 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 337 def show_exceptions? SHALL_WE_SHOW_EXCEPTIONS end |
#size? ⇒ Boolean Also known as: keys, size
#
size?
Query how many keys we have registered.
#
292 293 294 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 292 def size? keys?.size end |
#test(i = seek_this_key? ) ⇒ Object
#
test
#
328 329 330 331 332 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 328 def test( i = seek_this_key? ) verbose_points_to?(i) end |
#translate_key_into_value(key) ⇒ Object
#
translate_key_into_value
This method will NOT do any additional sanitizing. It will simply query the main hash, as-is.
#
259 260 261 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 259 def translate_key_into_value(key) @internal_hash[:dataset][key] end |
#verbose_points_to?(i = seek_which_key?) ) ⇒ Boolean
#
verbose_points_to?
#
488 489 490 491 492 493 494 495 496 497 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 488 def verbose_points_to?(i = seek_which_key?) i = i.to_s if is_included? i opnn; e "#{::Rcfiles.rev}Yes, the key `#{::Rcfiles.sfancy(i)}` is included." opnn; e "#{::Rcfiles.rev}It points to the directory: #{::Rcfiles.sdir(hash?[i])}" else opnn; e "#{::Rcfiles.rev}No, the key `#{::Rcfiles.sfancy(i)}` is not "\ "included in the cd-aliases." end end |