Sha256: 6b7d0e8c18955dc43eb65988b07c336dee0f77bf9acf6debb66453499b091ec9

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

module Redcar
  class Command
    class Executor
      include Redcar::Core::HasLogger
      
      def self.current_environment
        win = Redcar.app.focussed_window
        tab = Redcar.app.focussed_window.focussed_notebook.focussed_tab
        { :win => win,
          :tab => tab }
      end
      
      def initialize(command_instance, options={})
        @command_instance = command_instance
        @options          = options
      end
      
      def execute
        @command_instance.environment(Executor.current_environment)
        begin
          result = @command_instance.execute
        rescue Object => e
          @command_instance.error = e
          log_error
        rescue java.lang.StackOverflowError => e
          @command_instance.error = e
          log_error
        end
        record
        result
      end
      
      private
      
      def log_error
        logger.error "* Error in command #{@command_instance.class}"
        if @command_instance.error.respond_to?(:backtrace)
          logger.error "  " + @command_instance.error.message.to_s
          @command_instance.error.backtrace.each {|l| logger.error("  " + l) }
        end
      end
      
      def record
        if Redcar.app.history
          Redcar.app.history.record(@command_instance)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redcar-0.3.4.3 plugins/application/lib/application/command/executor.rb
redcar-0.3.4.2 plugins/application/lib/application/command/executor.rb
redcar-0.3.4.1 plugins/application/lib/application/command/executor.rb
redcar-0.3.4 plugins/application/lib/application/command/executor.rb
redcar-0.3.3 plugins/application/lib/application/command/executor.rb