Sha256: c9fea3d8e9562b1c96d2002bda146c304d3bec399dd1c20ad1d285693d8ddac5

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 Bytes

Contents

module JsTestDriver
  module Commands

    class BaseCommand
      def initialize(executable)
        @command = executable.to_s
        ensure_installed!

        @options = []
        @args = []
      end

      def option(name, value = nil)
        @options << name
        @options << escape(value)
        self
      end

      def arg(value)
        @args << escape(value)
        self
      end

      def to_s
        return ([@command] + @options + @args).compact.join(' ')
      end

      protected

      def executable_not_found!
        raise JsTestDriver::MissingDependencyError.new("Could not find executable: #{@command}")
      end

      private

      def installed?
        !%x[which #{@command}].strip.empty?
      end

      def ensure_installed!
        executable_not_found! unless installed?
      end

      def escape(value)
        return "'#{value}'" if value && value =~ /\s/
        return value
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
js-test-driver-rails-0.5.0.pre5 lib/js_test_driver/commands/base_command.rb
js-test-driver-rails-0.5.0.pre4 lib/js_test_driver/commands/base_command.rb
js-test-driver-rails-0.5.0.pre3 lib/js_test_driver/commands/base_command.rb