class RBT::Cookbooks::ToggleKeepExtractedValue
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
- REGEX_TO_OBTAIN_THE_BOOLEAN_VALUE_FROM_KEEP_EXTRACTED
#¶ ↑
REGEX_TO_OBTAIN_THE_BOOLEAN_VALUE_FROM_KEEP_EXTRACTED
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
backup_the_old_file()
click to toggle source
#¶ ↑
backup_the_old_file
(backup tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 208 def backup_the_old_file _ = path? if File.exist? _ new_target = rbt_log_dir?+'CookbookDirectory/'+File.basename(_) base_dir = File.dirname(new_target) silently_create_this_directory_if_it_does_not_yet_exist(base_dir) opnn; e "Now copying the #{orange('old')} file `#{sfile(_)}"\ "` to `#{sfile(new_target)}`." copy_file(_, new_target) end end
determine_the_path_to_the_yaml_file( i = return_location_to_this_programs_yaml_file(which_program?.delete('_-')) )
click to toggle source
#¶ ↑
determine_the_path_to_the_yaml_file
¶ ↑
This method will determine the path to the yaml file. Normally this will be at the individual cookbooks directory, but sometimes the user may want to use another path; thus explains why this method here exists.
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 111 def determine_the_path_to_the_yaml_file( i = return_location_to_this_programs_yaml_file(which_program?.delete('_-')) ) if i.nil? # In this case, use a default value. i = return_location_to_this_programs_yaml_file(which_program?.delete('_-')) end @use_this_path_to_the_yaml_file = i end
do_modify_this_program( this_program = which_program? )
click to toggle source
#¶ ↑
do_modify_this_program
¶ ↑
This is the do-action, the powerhorse method of this class.
It will combine the logic that is required in order to toggle the given value at hand.
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 128 def do_modify_this_program( this_program = which_program? ) location = @use_this_path_to_the_yaml_file if File.exist? location dataset = File.read(location) if dataset =~ /^ keep_extracted: / # =================================================================== # # Ok, the .yml file has a keep_extracted value, so we can continue. # We will apply a regex to grab the line. # =================================================================== # use_this_regex = use_which_regex? dataset =~ use_this_regex bool_value = $1.to_s.dup complement_to_the_bool_value = find_the_boolean_complement_to(bool_value) new_dataset = dataset.sub( use_this_regex, ' keep_extracted: '+complement_to_the_bool_value ) # =================================================================== # # Now we can store this dataset. # =================================================================== # store_this_dataset(new_dataset, location) if is_on_roebe? # ================================================================= # # Also store it on my home system: # ================================================================= # _ = DIRECTORY_INDIVIDUAL_COOKBOOKS_AT_ROEBE_HOME.dup location = _+File.basename(location) store_this_dataset(new_dataset, location) end else opnn; e "No entry for #{sfancy(' keep_extracted: ')} could be found." end else opnn; e 'No file exists at '+sfile(location)+'.' end end
find_the_boolean_complement_to(i)
click to toggle source
#¶ ↑
find_the_boolean_complement_to
¶ ↑
We honour the length - “f” will complement to “t”, and vice versa, and “false” will complement to “true”, and vice versa.
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 172 def find_the_boolean_complement_to(i) case i when 'f' 't' when 't' 'f' when 'false' 'true' when 'true' 'false' end end
modify_this_program?()
click to toggle source
#¶ ↑
modify_this_program?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 98 def modify_this_program? @modify_this_program end
Also aliased as: modify_which_program?, which_program?
reset()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 223 def run # ======================================================================= # # First, we must handle the case where the user provided no program name. # ======================================================================= # if modify_this_program? determine_the_path_to_the_yaml_file(@use_this_path_to_the_yaml_file) opnn; e 'We will next attempt to toggle the '+ orange('keep_extracted:')+' value' opnn; e "for the program #{sfancy(which_program?)}." do_modify_this_program end end
set_modify_this_program(i = nil)
click to toggle source
#¶ ↑
set_modify_this_program
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 79 def set_modify_this_program(i = nil) i = i.first if i.is_a? Array if i.nil? opnn; e "Please provide the #{simp('name of a program')} to this method." end i = i.to_s.dup unless i.nil? @modify_this_program = i if i and File.exist?(i) # ===================================================================== # # This entry point exists when the user input the location to # a real (local) file. # ===================================================================== # determine_the_path_to_the_yaml_file(@modify_this_program) end end
store_this_dataset( what, into = which_program? )
click to toggle source
#¶ ↑
store_this_dataset
¶ ↑
This method can be used to store the dataset into a file.
We will, however had, keep a backup file too.
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 192 def store_this_dataset( what, into = which_program? ) unless into.end_with? '.yml' into = into.dup if into.frozen? into << '.yml' end backup_the_old_file opnn; e 'Storing the new dataset into the file `'+sfile(into)+'`.' write_what_into(what, into) end
use_this_path_to_the_yaml_file?()
click to toggle source
#¶ ↑
use_this_path_to_the_yaml_file?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/toggle_keep_extracted_value.rb, line 65 def use_this_path_to_the_yaml_file? @use_this_path_to_the_yaml_file end
Also aliased as: path?
use_which_regex?()
click to toggle source