class RBT::UrlAction

Constants

ARRAY_ALLOWED_ACTIONS
#

ARRAY_ALLOWED_ACTIONS

#
DEFAULT_COLOUR
#

DEFAULT_COLOUR

#
EXTRACT_TO

Public Class Methods

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

RBT::UrlAction[]

#
# File lib/rbt/url_action/url_action.rb, line 439
def self.[](i = '')
  new(i)
end
allowed_actions?() click to toggle source
#

RBT::UrlAction.allowed_actions?

Query which actions are allowed for class RBT::UrlActin.

#
# File lib/rbt/url_action/url_action.rb, line 62
def self.allowed_actions?
  ARRAY_ALLOWED_ACTIONS
end
compile_mode?() click to toggle source
#

UrlAction.compile_mode?

#
# File lib/rbt/url_action/url_action.rb, line 86
def self.compile_mode?
  @compile_mode
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

The input can also include a version-component of a given program, such as “1.5.22”.

If the program version is omitted, we will default to the latest version that is registered.

#
# File lib/rbt/url_action/url_action.rb, line 113
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end
set_compile_mode( i = :rbt ) click to toggle source
#

UrlAction.set_compile_mode

We need to keep track whether we wish to use Easycompile or RBT.

We do this by assigning to the @compile_mode variable. The three valid settings are nil, :rbt and :easycompile.

#
# File lib/rbt/url_action/url_action.rb, line 98
def self.set_compile_mode(
    i = :rbt
  )
  @compile_mode = i
end

Public Instance Methods

action_to_perform?() click to toggle source
#

action_to_perform?

#
# File lib/rbt/url_action/url_action.rb, line 220
def action_to_perform?
  _ = input?
  if _.include? '/'
    _ = _.split('/').first
  end
  _ # Return it here.
end
debug?() click to toggle source
#

debug?

#
# File lib/rbt/url_action/url_action.rb, line 178
def debug? # Whether we will debug or whether we will not.
  @debug
end
easycompile( i, program_version = nil ) click to toggle source
#

easycompile

Delegate to the easycompile project in order to compile something from source.

#
# File lib/rbt/url_action/url_action.rb, line 360
def easycompile(
    i, program_version = nil
  )
  begin
    require 'easycompile' unless Object.const_defined? :Easycompile
  rescue LoadError; end
  # ======================================================================= #
  # We assume that the user wishes to use a yaml file here.
  # This is a typical operation for Easycompile.
  # ======================================================================= #
  i << '.yml' unless i.end_with? '.yml'
  if program_version
    Easycompile::Easycompile.new(i,
      extract_to:      extract_to?,
      program_version: program_version,
      prefix:          :appdir_layout
    )
  else
    Easycompile::Easycompile.new(i,
      extract_to: extract_to?,
      prefix:     :appdir_layout
    )
  end
end
extract_to?() click to toggle source
#

extract_to?

#
# File lib/rbt/url_action/url_action.rb, line 213
def extract_to?
  @extract_to
end
input?() click to toggle source
#

input?

#
# File lib/rbt/url_action/url_action.rb, line 388
def input?
  @input
end
install_this_program(i, program_version = nil) click to toggle source
#

install_this_program (install tag, compile tag)

This will compile/install a given program.

We also have to support installation of a specific version.

#
# File lib/rbt/url_action/url_action.rb, line 399
def install_this_program(i, program_version = nil)
  if i.is_a? Array
    i.each {|entry| install_this_program(entry) }
  else
    compile_mode = RBT::UrlAction.compile_mode?
    set_result('Now installing `'+sfancy(i)+'` via '+compile_mode.to_s+'.')
    opn; e result?
    case compile_mode
    when :rbt # rbt tag.
      require 'rbt/requires/require_the_installer_class.rb'
      _ = RBT::Action::Installer.new(i, :dont_run_yet)
      _.extract_to extract_to?
      _.run
    when :easycompile # Easycompile tag.
      # =================================================================== #
      # If the input includes a '-' then we assume that the user
      # wants to install a specific version.
      # =================================================================== #
      if i.include? '-'
        program_version = i.split('-')
        opn; e 'We will use version number `'+sfancy(program_version)+
               '` if possible.'
        easycompile(i, program_version)
      else
        easycompile(i)
      end
    end
  end
end
query_package(this_package) click to toggle source
#

query_package

This method will return a listing of all versioned directories found under the $PROGRAMS/Foo directory.

#
# File lib/rbt/url_action/url_action.rb, line 258
def query_package(this_package)
  if this_package.is_a? Array
    this_package.each {|package| query_package(package) }
  else
    opne "Querying package `#{sfancy(this_package)}` next."
    location = (programs_dir?+this_package.capitalize+'/').squeeze '/'
    if File.exist? location
      _ = Dir[location+'*'].select {|i| i =~ /\d+/ } # Select entries with a number.
      if _.empty? # Do nothing if it is empty.
      else
        reset_result
        @result << "#{N}Found these packages:"
        efancy @result
        _.each {|package|
          string = '  → '+package
          @result << string
          e string
        }
      end
    else
      @result = "  The location `#{location}` does not exist."
      opnwarn @result
    end
  end
end
remove_this_program(i) click to toggle source
#

remove_this_program (remove tag)

Remove a package/program through this method.

We need to be sure that a specific version is mentioned, too. If it is not then we will remove all versions.

#
# File lib/rbt/url_action/url_action.rb, line 292
def remove_this_program(i)
  if i.is_a? Array
    i.each {|my_program|
      remove_this_program(my_program)
    }
  else
    i = programs_dir?+i.capitalize
    if File.exist? i
      opne "Removing `#{sdir(i)}` now."
      remove_directory(i) # Remove a directory here.
      possible_current_symlink = i.split('/')[0..-2].join('/')+'/Current'
      if File.symlink? possible_current_symlink
        File.delete(possible_current_symlink)
      end
    else
      @result = i+' not found. Can not remove.'
      opne @result
    end
  end
end
report_unknown_action( i = nil ) click to toggle source
#

report_unknown_action

Presently, only these three actions are known:

- query
- remove
- install

A few aliases exist to these actions, such as ‘_’ and ‘?’.

#
# File lib/rbt/url_action/url_action.rb, line 200
def report_unknown_action(
    i = nil
  )
  i = i.to_s unless i.is_a? String # Need a String.
  unless i.empty?
    set_result 'The action called `'+i+'` is unknown.'
    e @result
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/url_action/url_action.rb, line 132
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @result
  # ======================================================================= #
  @result      = nil
  # ======================================================================= #
  # === @input
  # ======================================================================= #
  @input       = nil
  # ======================================================================= #
  # === :debug
  # ======================================================================= #
  enable_debug
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose
  # ======================================================================= #
  # === :use_colours
  # ======================================================================= #
  enable_colours # Whether to use colours or not.
  set_extract_to # Must initialize it once.
  RBT::UrlAction.set_compile_mode :rbt # Initialize it to this default.
end
reset_result() click to toggle source
#

reset_result

#
# File lib/rbt/url_action/url_action.rb, line 248
def reset_result
  @result = nil
end
result()
Alias for: result?
result?() click to toggle source
#

result?

#
# File lib/rbt/url_action/url_action.rb, line 241
def result?
  @result
end
Also aliased as: result
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/url_action/url_action.rb, line 432
def run
  run_everything
end
run_everything() click to toggle source
#

run_everything (action tag, act tag)

This is the powerhorse of the project.

#
# File lib/rbt/url_action/url_action.rb, line 318
def run_everything
  _ = action_to_perform?.to_sym
  if RBT::UrlAction.allowed_actions?.include? _
    this_program = nil
    # ===================================================================== #
    # Ok, the action is allowed, thus we can continue.
    # ===================================================================== #
    which_action_to_perform = input?
    if which_action_to_perform.include? '/'
      splitted = which_action_to_perform.split('/')
      splitted.reject!(&:empty?) # Get rid of empty entries.
      which_action_to_perform = splitted.first # Grab the first entry.
      this_program = splitted[1]
    end
    case which_action_to_perform # case tag
    # ===================================================================== #
    # === query
    # ===================================================================== #
    when 'query','q','?' # ? is also treated as a query
      query_package(this_program)
    # ===================================================================== #
    # === remove
    # ===================================================================== #
    when 'remove','rm','entferne','lösche'
      remove_this_program(this_program)
    # ===================================================================== #
    # === install
    # ===================================================================== #
    when 'install','i','compile','_'
      install_this_program(this_program)
    end
  else # Else the action is not included.
    report_unknown_action _
  end
end
set_action(i = '')
Alias for: set_input
set_extract_to(i = EXTRACT_TO) click to toggle source
#

set_extract_to

Defaults to /Depot/Temp for extracting.

#
# File lib/rbt/url_action/url_action.rb, line 233
def set_extract_to(i = EXTRACT_TO)
  i = EXTRACT_TO if i.nil?
  @extract_to = i
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/rbt/url_action/url_action.rb, line 162
def set_input(i = '')
  i = i.join(' ').strip if i.is_a? Array
  i = i.to_s.dup # Must be a String.
  # ======================================================================= #
  # Eliminate leading '/' characters. We never need them really.
  # ======================================================================= #
  i[0,0] = '' if i.start_with? '/'
  if debug? and i and !i.nil? and !i.empty?
    opne "Now setting the input to `#{sfancy(i)}`."
  end
  @input = i
end
Also aliased as: set_action
set_result(i) click to toggle source
#

set_result

#
# File lib/rbt/url_action/url_action.rb, line 185
def set_result(i)
  @result = i
end