class RBT::ChangePrefix

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

RBT::ChangePrefix[]

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 292
def self.[](i = '')
  self.new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 44
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 117
def commandline_arguments?
  @commandline_arguments
end
main_file?()
Alias for: modify_this_file?
menu( i = @commandline_arguments ) click to toggle source
#

menu (menu tag)

#
modify_this_file?() click to toggle source
#

modify_this_file?

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 108
def modify_this_file?
  @modify_this_file
end
modify_which_file?()
Alias for: modify_this_file?
of_this_makefile()
Alias for: modify_this_file?
perform_the_modification() click to toggle source
#

perform_the_modification

This is the method that will be used to modify

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 135
def perform_the_modification
  _ = main_file?
  if File.exist? _
    old_dataset = File.readlines(_)
    pattern = @search_for_this_pattern
    joined_dataset = old_dataset.join("\n")
    if joined_dataset =~ pattern # Must be a Regex.
      opnn; e 'A match was found within the file '+sfile(_)+'.'
      new_file_content = ''.dup
      old_dataset.each {|line|
        if line =~ pattern
          # =============================================================== #
          # Here we have to check for two cases:
          #
          #   1) prefix is downcased
          #   2) PREFIX is upcased
          # =============================================================== #
          if line.include? 'prefix '
            # ============================================================= #
            # Then use the downcased variant.
            # ============================================================= #
            line = 'prefix = '+@use_this_as_the_new_prefix
          elsif line.include? 'PREFIX='
            line = 'PREFIX = '+@use_this_as_the_new_prefix
          else
            # ============================================================= #
            # Else use the upcased variant.
            # ============================================================= #
            line = 'PREFIX = '+@use_this_as_the_new_prefix
          end
        end
        new_file_content << "#{line.rstrip}\n"
      }
      opnn; e "Storing into the file `#{sfile(_)}`."
      write_what_into(new_file_content, _)
    else
      opnn; e 'The pattern '+sfancy(pattern)+' could '\
              'not be found in the file '+sfile(_)+'.'
    end
  else
    opnn; no_file_exists_at(_)
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/change_prefix.rb, line 58
def reset
  super()
  @namespace = NAMESPACE
  # ======================================================================= #
  # Designate which file is to be modified next:
  # ======================================================================= #
  set_modify_this_file(:default_file)
  # ======================================================================= #
  # Designate which pattern we are trying to find in that file.
  #
  # Unfortunately there does not seem to be a general consensus in
  # what is allowed and what is not. For example, the program called
  # 'mxk-1.10' makes use of exactly this line "prefix  = /usr/local",
  # whereas the program called 'libcli-1.9.8-4' makes use of exactly
  # this line "PREFIX = /usr/local". Thus, we will have to check for
  # these variants, which is why we will ask rubular for help here.
  #
  # See:
  #
  #   https://rubular.com/r/iAYqSQTaSllK5f
  #
  # ======================================================================= #
  @search_for_this_pattern = /^(PREFIX\s*=) ?(.+)/i
  # ======================================================================= #
  # Infer the name and program version from Dir.pwd, via ProgramInformation.
  # ======================================================================= #
  program_information = ProgramInformation.new(Dir.pwd)
  version = program_information.version?
  name    = program_information.program_name?
  @use_this_as_the_new_prefix = 
    rds(
      programs_dir?+
      name.capitalize+'/'+
      version+'/'
    )
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 284
def run
  menu
  perform_the_modification
end
set_commandline_arguments(i = '') click to toggle source
#

set_input

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 229
def set_commandline_arguments(i = '')
  if i.is_a? Hash
    # ===================================================================== #
    # If a Hash is given then we will modify this Hash a bit before
    # continuing here.
    # ===================================================================== #
    if i.has_key? :use_this_makefile
      set_modify_this_file(
        i.delete(:use_this_makefile)
      )
    end
    # ===================================================================== #
    # Query for another prefix that is to be used next:
    # ===================================================================== #
    if i.has_key? :use_this_as_the_new_prefix
      new_value = i.delete(:use_this_as_the_new_prefix)
      set_use_this_as_the_new_prefix(new_value)
    end
  end
  i = [i].flatten.compact
  if i.empty?
    # ===================================================================== #
    # In that case we will attempt to use a Makefile in the current
    # directory.
    # ===================================================================== #
    i << 'Makefile'
  end
  @commandline_arguments = i
end
set_main_file(i = :default)
set_modify_this_file(i = :default) click to toggle source
#

set_modify_this_file

This method can be used to designate where the target “Makefile” is exactly.

Do note that set_main_file() is an alias to this method here.

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 267
def set_modify_this_file(i = :default)
  case i
  when :default,
       :default_file
    i = '/Depot/jjj/libcli-1.9.8-4/Makefile' 
  end
  i = i.dup if i.frozen?
  unless i.include? '/'
    i = File.absolute_path(i)
  end
  i = rds(i)
  @modify_this_file = i
end
Also aliased as: set_main_file
set_use_this_as_the_new_prefix(i) click to toggle source
#

set_use_this_as_the_new_prefix

This method can be used to designate another prefix that is to be used - the one that will be written into the “Makefile”.

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 101
def set_use_this_as_the_new_prefix(i)
  @use_this_as_the_new_prefix = i
end
show_help() click to toggle source
#

show_help

#
# File lib/rbt/utility_scripts/change_prefix.rb, line 124
def show_help
  e
  e 'Presently this class has no help option documented.'
  e
end