class RBT::Cookbooks::ToggleKeepExtractedValue

Constants

REGEX_TO_OBTAIN_THE_BOOLEAN_VALUE_FROM_KEEP_EXTRACTED
#

REGEX_TO_OBTAIN_THE_BOOLEAN_VALUE_FROM_KEEP_EXTRACTED

#

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::Cookbooks::ToggleKeepExtractedValue[]

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 252
def self.[](i = ARGV)
  new(i)
end
new( of_this_program = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 43
def initialize(
    of_this_program = nil,
    run_already     = true
  )
  reset
  set_modify_this_program(
    of_this_program
  )
  run if run_already
end

Public Instance Methods

backup_the_old_file() click to toggle source
#

backup_the_old_file (backup tag)

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 221
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)
    opne "#{rev}Now copying the #{orange('old')} #{rev}file "\
         "`#{sfile(_)}#{rev}` to `#{sfile(new_target)}#{rev}`."
    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/cookbooks/toggle_keep_extracted_value.rb, line 116
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/cookbooks/toggle_keep_extracted_value.rb, line 133
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
      opne "#{rev}No entry for #{sfancy(' keep_extracted: ')} "\
           "#{rev}could be found."
    end
  else
    no_file_exists_at(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/cookbooks/toggle_keep_extracted_value.rb, line 178
def find_the_boolean_complement_to(i)
  case i
  when 'f'
    't'
  when 't'
    'f'
  when 'false'
    'true'
  when 'true'
    'false'
  when 'yes'
    'no'
  when 'no'
    'yes'
  else
    e "Unhandled cased: #{steelblue(i.to_s)}"
  end
end
modify_this_program?() click to toggle source
#

modify_this_program?

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 103
def modify_this_program?
  @modify_this_program
end
modify_which_program?()
path?()
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 57
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @use_this_path_to_the_yaml_file
  # ======================================================================= #
  @use_this_path_to_the_yaml_file = nil
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 236
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)
    opne 'We will next attempt to toggle the '+
          orange('keep_extracted:')+' value'
    opne "#{rev}for the program #{sfancy(which_program?)}#{rev}."
    do_modify_this_program
  end
end
set_modify_this_program(i = nil) click to toggle source
#

set_modify_this_program

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 83
def set_modify_this_program(i = nil)
  i = i.first if i.is_a? Array
  if i.nil?
    opne "#{rev}Please provide the #{simp('name of a program')} "\
         "#{rev}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/cookbooks/toggle_keep_extracted_value.rb, line 204
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
  opne "#{steelblue('Storing the new dataset')} #{rev}into "\
       "the file `#{sfile(into)}#{rev}`."
  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/cookbooks/toggle_keep_extracted_value.rb, line 69
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
#

use_which_regex?

#
# File lib/rbt/cookbooks/toggle_keep_extracted_value.rb, line 76
def use_which_regex?
  REGEX_TO_OBTAIN_THE_BOOLEAN_VALUE_FROM_KEEP_EXTRACTED
end
which_program?()