Class: Redcar::FilterCommand::Evaluator
- Inherits:
-
Object
- Object
- Redcar::FilterCommand::Evaluator
- Defined in:
- lib/filter_command/evaluator.rb
Overview
The command parser and runner for FilterCommand
Class Method Summary collapse
-
.evaluate(command, input, output) ⇒ Object
Command processing before execution.
-
.execute_command(window, command, input, output) ⇒ Object
The actual running of a command filter speedbar.
-
.format_text(text, format) ⇒ Object
Command post-processing.
-
.input_types ⇒ Object
List of supported input types for command execution.
-
.set_path(command, path) ⇒ Object
Sets the working directory for a given command to a given path, and adds proper escaping (platform-specific).
Class Method Details
.evaluate(command, input, output) ⇒ Object
Command processing before execution. If successful, the given command is run.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/filter_command/evaluator.rb', line 17 def self.evaluate(command,input,output) win = Redcar.app.focussed_window tab = win.focussed_notebook_tab original_command = command.clone if tab and tab.is_a?(Redcar::EditTab) and doc = tab.edit_view.document case input when "None" # do nothing when "Selection" if doc.selection? selection = doc.selected_text else selection = doc.get_line_without_end_of_line(doc.cursor_line) end command = pipe_text(selection, command) when "Document" command = pipe_text(doc.get_all_text, command) when "Cursor Line" command = pipe_text(doc.get_line_without_end_of_line(doc.cursor_line), command) when "Cursor Word" command = pipe_text(doc.current_word, command) else raise "Unknown input type found: #{input}" end result = FilterCommand::CommandParser.substitute_variables(doc,command) command = result['command'] temp = result['temp'] elsif input != "None" tab_type_error input return end execute_command win, command, input, output if temp and File.exist?(temp) Redcar::Project::Manager.open_file(temp) end FilterCommand::History.update_commands original_command, input, output end |
.execute_command(window, command, input, output) ⇒ Object
The actual running of a command filter speedbar. If the current window has a project open, the process working directory will be the project directory.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/filter_command/evaluator.rb', line 60 def self.execute_command window, command, input, output if project = Project::Manager.in_window(window) command = set_path command, project.path end pid, io_input, io_output, io_error = IO.popen4(command) if error = io_error.read and error.empty? format_text(io_output.read, output) else Redcar::Application::Dialog.(error, :type => :error) end end |
.format_text(text, format) ⇒ Object
Command post-processing.
75 76 77 78 79 80 81 |
# File 'lib/filter_command/evaluator.rb', line 75 def self.format_text text, format if format_class = OutputFormat.formats[format] format_class.new.format(text,format) else raise "Unknown output type found: #{format}" end end |
.input_types ⇒ Object
List of supported input types for command execution
8 9 10 |
# File 'lib/filter_command/evaluator.rb', line 8 def self.input_types ['None','Selection','Document','Cursor Line','Cursor Word'] end |
.set_path(command, path) ⇒ Object
Sets the working directory for a given command to a given path, and adds proper escaping (platform-specific).
87 88 89 90 91 92 93 94 95 |
# File 'lib/filter_command/evaluator.rb', line 87 def self.set_path command, path case Redcar.platform when :osx, :linux command = "sh -c \"cd \\\"#{path}\\\" && #{command}\"" when :windows command = "cd \"#{path.gsub('/', '\\')}\" & #{command}" end command end |