Sha256: 744404b78204659ea525c1550766133ee6bb33fb5de05770e77c2eaa98b267ad

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require_relative 'command/rails'
require_relative 'command/rake'
require_relative 'command/rspec'
require_relative 'command/ruby'

module Retest
  class Command
    extend Forwardable

    def self.for_options(options, stdout: $stdout)
      new(options: options, stdout: stdout).command
    end

    def_delegator :setup, :type
    def_delegators :options, :params, :full_suite?, :auto?

    attr_accessor :options, :setup
    def initialize(options: Options.new, setup: Setup.new, stdout: $stdout)
      @options = options
      @setup = setup
      @stdout = stdout
    end

    def command
      options_command || default_command
    end

    def options_command
      return params[:command] if params[:command]

      if    params[:rspec] then rspec_command
      elsif params[:rails] then rails_command
      elsif params[:ruby]  then ruby_command
      elsif params[:rake]  then rake_command
      else
      end
    end

    def setup_command
      case type
      when :rake  then rake_command
      when :rspec then rspec_command
      when :rails then rails_command
      when :ruby  then ruby_command
      else             ruby_command
      end
    end

    def default_command
      log "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
      setup_command
    end

    private

    def log(message)
      @stdout&.puts(message)
    end

    def rspec_command
      Rspec.new(all: full_suite?)
    end

    def rails_command
      Rails.new(all: full_suite?)
    end

    def rake_command
      Rake.new(all: full_suite?)
    end

    def ruby_command
      Ruby.new(all: full_suite?)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
retest-2.0.0.pre3 lib/retest/command.rb
retest-2.0.0.pre2 lib/retest/command.rb
retest-2.0.0.pre1 lib/retest/command.rb