class RBT::UrlAction
Constants
- ARRAY_ALLOWED_ACTIONS
#¶ ↑
ARRAY_ALLOWED_ACTIONS
¶ ↑#¶ ↑
- DEFAULT_COLOUR
#¶ ↑
DEFAULT_COLOUR
¶ ↑#¶ ↑
- EXTRACT_TO
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
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 58 def initialize( i = nil, run_already = true ) reset set_input(i) run if run_already end
#¶ ↑
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/compile_mode.rb, line 33 def self.set_compile_mode( i = :rbt ) @compile_mode = i end
Public Instance Methods
#¶ ↑
easycompile¶ ↑
Delegate to the easycompile project in order to compile something from source.
#¶ ↑
# File lib/rbt/url_action/url_action.rb, line 267 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
#¶ ↑
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 306 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. _ = RBT::Compile.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 method will return a listing of all versioned directories found under the $PROGRAMS/Foo directory.
#¶ ↑
# File lib/rbt/url_action/url_action.rb, line 165 def query_package(this_package) if this_package.is_a? Array this_package.each {|package| query_package(package) } else opnn; e "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.' opnn; ewarn @result end end end
#¶ ↑
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 199 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 opnn; e "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.' opnn; e @result end end end
#¶ ↑
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 107 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 (reset tag)¶ ↑
#¶ ↑
RBT::Base#reset
# File lib/rbt/url_action/url_action.rb, line 70 def reset super() @namespace = NAMESPACE @result = nil @input = nil @debug = true @be_verbose = true @use_colours = true # 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
#¶ ↑
run_everything
(action tag, act tag)¶ ↑
This is the powerhorse of the project.
#¶ ↑
# File lib/rbt/url_action/url_action.rb, line 225 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_input
¶ ↑
#¶ ↑
# File lib/rbt/url_action/url_action.rb, line 338 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? opnn; e "Now setting the input to `#{sfancy(i)}`." end @input = i end