Class: CLApp
- Inherits:
-
Object
- Object
- CLApp
- Defined in:
- lib/rakeutils/clapp.rb
Overview
Base class that provides common functionality for command line application caller classes.
Direct Known Subclasses
InnoTask, JJTreeTask, JavaCCTask, OcraTask, Tex2Rtf, ZipTask
Instance Method Summary collapse
-
#execute(cmd_line, can_throw = true) ⇒ Object
Execute application.
-
#initialize(app_path) ⇒ CLApp
constructor
- Constructor app_path
-
absolute path to application to control.
-
#normalize_dir_path(dirpath) ⇒ Object
Return a normalized directory path (if the path is to a file, return the file’s directory).
-
#quote_all_values(values) ⇒ Object
- Apply quotes around an array of text values (helper function) values
- Value to apply quotes to returns
-
quoted value.
-
#quote_value(val) ⇒ Object
- Apply quotes around a text value (helper function for GLT class) val
- Value to apply quotes to returns
-
quoted value.
-
#rubyize_path(path) ⇒ Object
Convert windows path seperators to ruby (backslash to forward slash).
-
#windowize_path(path) ⇒ Object
Convert ruby path seperators to windows ( forward slash to backslash).
Constructor Details
#initialize(app_path) ⇒ CLApp
Constructor
- app_path
-
absolute path to application to control
18 19 20 |
# File 'lib/rakeutils/clapp.rb', line 18 def initialize(app_path) @app_path = app_path end |
Instance Method Details
#execute(cmd_line, can_throw = true) ⇒ Object
Execute application.
- cmd_line
-
Command line to pass to the application
- can_throw
-
If true, throw exception if command fails.
- throws
-
Exception if command failed.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rakeutils/clapp.rb', line 80 def execute(cmd_line, can_throw=true) app_cmd = "#{@app_path} #{cmd_line}" puts "Executing: #{app_cmd}" if( !File.exists?(@app_path) ) raise "Invalid application path: #{@app_path}" end if( !Kernel.system("#{app_cmd}") && can_throw ) raise "Application threw an exception for the command: ".concat(app_cmd) end end |
#normalize_dir_path(dirpath) ⇒ Object
Return a normalized directory path (if the path is to a file, return the file’s directory). This will make sure that the path is quoted if it contains spaces.
- dirpath
-
Path to directory
- returns
-
Path to directory
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rakeutils/clapp.rb', line 46 def normalize_dir_path(dirpath) if (!File.directory?(dirpath)) # This is not a path to a directory... if(File.exists?(dirpath)) dirpath = File.dirname(dirpath) end end if(!dirpath.include?('"') && !dirpath.include?("'")) # Do not add quotes around path if it already contains quotes. if(dirpath.include?(' ')) # Add quotes around path if it contains spaces. dirpath = quote_value(dirpath) end end return dirpath end |
#quote_all_values(values) ⇒ Object
Apply quotes around an array of text values (helper function)
- values
-
Value to apply quotes to
- returns
-
quoted value
34 35 36 37 38 39 40 41 |
# File 'lib/rakeutils/clapp.rb', line 34 def quote_all_values(values) q_vals = [] values.each do |val| q_vals << quote_value(val) end return q_vals end |
#quote_value(val) ⇒ Object
Apply quotes around a text value (helper function for GLT class)
- val
-
Value to apply quotes to
- returns
-
quoted value
25 26 27 28 29 |
# File 'lib/rakeutils/clapp.rb', line 25 def quote_value(val) q_vals = '"' + "#{val}" + '"' return q_vals end |
#rubyize_path(path) ⇒ Object
Convert windows path seperators to ruby (backslash to forward slash).
- path
-
path to convert
- returns
-
converted path
65 66 67 |
# File 'lib/rakeutils/clapp.rb', line 65 def rubyize_path(path) return path.gsub(/\\/, "/") end |
#windowize_path(path) ⇒ Object
Convert ruby path seperators to windows ( forward slash to backslash).
- path
-
path to convert
- returns
-
converted path
72 73 74 |
# File 'lib/rakeutils/clapp.rb', line 72 def windowize_path(path) return path.gsub(/\//, "\\") end |