Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Commands refactoring using Executor superclass #183

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

All commands should inherit from this Executor class. Each command class should have a #run method.
The ouput is set to $stdout when calling super. The method #print will print out to console and #system_exec is in charge of executing system commands. This all makes for a much cleaner and DRY design and makes it easy to add new Commands.

class Jeweler
  module Commands
    class Executor
      attr_accessor :output

      def initialize
        self.output = $stdout
      end      

      def run
        raise "Must be implemented by subclass"
      end
      
      protected

      def print msg
        output.puts msg
      end

      def system_exec command
        print "Executing #{command.inspect}:"
        Kernel::system command
      end
    end
  end
end
Owner

technicalpickles commented May 30, 2011

To be fair, new commands aren't added that often so it's not a huge pain point. It does make it more obvious what commands do though.

This is really the Command pattern, so I would suggest renaming Executor to Command though, or maybe Base, or BaseCommand

Owner

technicalpickles commented Mar 18, 2016

I'm closing out old PRs as part of #283 . I'm sorry I was never able to help get this to a point to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment