Sha256: c64f0f8faa0b2b5d6236ee0dc66035695f5842de4eef8542c06344699b4a9ff8

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

module InfinityTest
  module Builder

    #
    # TODO: Refactoring this Ugly Code
    #
    #
    def construct_command(options)
      binary_name, ruby_version, command, file, environment = resolve_options(options)
      
      unless have_binary?(binary_name) || options[:skip_binary?]
        print_message(binary_name, ruby_version)
        
      else
        command = "#{command} #{decide_files(file)}"
        rvm_ruby_version = "rvm #{ruby_version} ruby"
        
        if application.have_gemfile? and not application.skip_bundler?
          run_with_bundler!(rvm_ruby_version, command, environment)
        else
          run_without_bundler!(rvm_ruby_version, command)
        end
        
      end
    end

    #
    def run_with_bundler!(rvm_ruby_version, command, environment)
      bundle_binary = search_bundle(environment)
      unless have_binary?(bundle_binary)
        print_message('bundle', environment.expanded_name)
      else
        %{#{rvm_ruby_version} #{bundle_binary} exec #{command}}
      end
    end

    #
    def run_without_bundler!(rvm_ruby_version, command)
      %{#{rvm_ruby_version} #{command}}
    end

    #
    # Contruct all the Commands for each ruby instance variable
    # If don't want to run with many rubies, add the current ruby to the rubies instance
    # and create the command with current ruby
    #
    def construct_commands(file=nil)
      @rubies << RVM::Environment.current.environment_name if @rubies.empty?
      construct_rubies_commands(file)
    end

    #
    # TODO: Refactoring this Ugly Code
    #
    #
    def resolve_options(options)
      ruby_version = options[:for]
      binary_name = options[:skip_binary?] ? '' : options[:binary]
      load_path = %{-I"#{options[:load_path]}"} if options[:load_path]
      environment = options[:environment]
      file = options[:file]
      command = [ binary_name, load_path].compact.join(' ')
      [binary_name, ruby_version, command, file, environment]
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infinity_test-1.0.2 lib/infinity_test/builder.rb
infinity_test-1.0.1 lib/infinity_test/builder.rb