class 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 209 def backup_the_old_file _ = path? if File.exist? _ new_target = CookbookDirectory?+File.basename(_) 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 = individual_cookbooks_dir?+which_program?.delete('_-')+'.yml' )
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/cookbooks/misc/toggle_keep_extracted_value.rb, line 115 def determine_the_path_to_the_yaml_file( i = individual_cookbooks_dir?+which_program?.delete('_-')+'.yml' ) if i.nil? # In this case, use a default value. i = individual_cookbooks_dir?+which_program?.delete('_-')+'.yml' 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 132 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? _ = RUBY_SRC_DIR_AT_HOME+'cookbooks/lib/cookbooks/yaml/individual_cookbooks/'.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/cookbooks/misc/toggle_keep_extracted_value.rb, line 173 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 95 def modify_this_program? @modify_this_program end
Also aliased as: modify_which_program?, which_program?
opnn()
click to toggle source
reset()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/cookbooks/misc/toggle_keep_extracted_value.rb, line 222 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 76 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 193 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/cookbooks/misc/toggle_keep_extracted_value.rb, line 62 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