class RBT::ApplySedOperations

Public Class Methods

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

RBT::ApplySedOperations[]

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 194
def self.[](i = ARGV)
  new(i)
end
new( apply_sed_operation_to_these_programs = ARGV, run_already = true, &block ) click to toggle source
#

initialize

The first argument to this method will be the sed-operations that this class will perform. It should be an Array, but if a String is given then it will be converted into an Array anyway.

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 31
def initialize(
    apply_sed_operation_to_these_programs = ARGV,
    run_already                          = true,
    &block
  )
  reset
  set_apply_sed_operation_to_these_programs(
    apply_sed_operation_to_these_programs
  )
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

apply_sed_operation_to_these_programs?() click to toggle source
#

apply_sed_operation_to_these_programs?

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 78
def apply_sed_operation_to_these_programs?
  @apply_sed_operation_to_these_programs
end
Also aliased as: use_which_sed_operations?
notify_the_user_what_will_happen_next() click to toggle source
#

notify_the_user_what_will_happen_next

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 172
def notify_the_user_what_will_happen_next
  opne "#{rev}Trying to use the #{teal('sed')} "\
       "#{rev}binary next, from the"
  opne "directory `#{sdir_return_pwd}#{rev}`."
end
obtain_sed_entries_for_this_program(i) click to toggle source
#

obtain_sed_entries_for_this_program

This method will obtain the particular sed-entries for the given program at hand.

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 88
def obtain_sed_entries_for_this_program(i)
  if i.start_with? ':'
    i = i.dup if i.frozen?
    i[0,1] = ''
  end
  dataset = actions(:SanitizeCookbook, i) { :fast }
  dataset.sed?
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 53
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @apply_sed_operation_to_these_programs
  # ======================================================================= #
  @apply_sed_operation_to_these_programs = nil
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 181
def run
  _ = use_which_sed_operations?
  unless _.empty?
    notify_the_user_what_will_happen_next
    _.each {|run_this_sed_operation|
      run_this_individual_sed_operation(run_this_sed_operation)
    }
  end
end
run_this_individual_sed_operation(run_this_sed_operation) click to toggle source
#

run_this_individual_sed_operation

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 141
def run_this_individual_sed_operation(run_this_sed_operation)
  # ======================================================================= #
  # Since as of December 2019, if we are on roebe, we will also
  # check whether we are working on an existing file. If so then we
  # will check whether we have done any change.
  # ======================================================================= #
  if is_on_roebe? and run_this_sed_operation.include? ' '
    possible_filename = run_this_sed_operation.split(' ').last
    if File.exist? possible_filename
      possible_dataset_from_that_file_before = File.read(possible_filename)
    end
  end
  e
  e skyblue("  #{run_this_sed_operation}")
  e
  system(run_this_sed_operation)
  if is_on_roebe? and run_this_sed_operation.include?(' ') and
     File.exist?(possible_filename)
    possible_dataset_from_that_file_after = File.read(possible_filename)
    if (possible_dataset_from_that_file_after == possible_dataset_from_that_file_before)
      opne rev+'No change has been made to the assumed filename '+sfile(possible_filename)+rev+'.'
    else
      opne rev+'The file content of '+sfile(possible_filename)+
           " #{rev}was modified."
    end
  end
end
sanitize_sed_operations() click to toggle source
#

sanitize_sed_operations

This method may modify the sed-commands residing in the individual .yml cookbook file.

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 103
def sanitize_sed_operations
  @apply_sed_operation_to_these_programs.map! {|entry|
    if entry.is_a? String
      if entry.start_with? ':' # ← Assume a Symbol in this case.
        # ================================================================= #
        # Specific usage example for this entry point:
        #
        #   applysed :libtheora
        #
        # ================================================================= #
        entry = obtain_sed_entries_for_this_program(entry)
      else
        # ================================================================= #
        # We assume that in this entry point no modifications will have
        # to be made.
        # ================================================================= #
        if entry.start_with? 'sed '
        # ================================================================= #
        # Else it could be a directory, or a String.
        # ================================================================= #
        elsif entry.include? '/'
          # =============================================================== #
          # Assume a directory in this case.
          # =============================================================== #
          entry = File.basename(entry)
        else
          entry = obtain_sed_entries_for_this_program(entry)
        end
      end
    end
    entry
  }
  @apply_sed_operation_to_these_programs.flatten! # ← Must invoke this again due to the ^^^ above code.
end
set_apply_sed_operation_to_these_programs( i = get_pwd ) click to toggle source
#

set_apply_sed_operation_to_these_programs

Use the sed operations for these programs.

#
# File lib/rbt/utility_scripts/apply_sed_operations.rb, line 67
def set_apply_sed_operation_to_these_programs(
    i = get_pwd
  )
  i = [i].flatten.compact # ← Must be an Array.
  @apply_sed_operation_to_these_programs = i
  sanitize_sed_operations # Sanitize the input a bit.
end
use_which_sed_operations?()