module Evrone module CI class Router module Middleware::Travis Ruby = Struct.new(:app) do include Helper::TraceShCommand def call(env) if rvm env env.init.tap do |i| i << 'eval "$(rbenv init -)" || true' i << "rbenv shell #{make_rbenv_version_command env}" i << 'export BUNDLE_GEMFILE=${PWD}/Gemfile' i << 'export GEM_HOME=/tmp/.rubygems' end env.before_install.tap do |b| b << "gem query -q -in '^bundler$' > /dev/null || gem install bundler -q --no-rdoc --no-ri" b << trace_sh_command("ruby --version") b << trace_sh_command("gem --version") b << trace_sh_command("bundle --version") end env.install.tap do |i| i << trace_sh_command("bundle install") end end app.call(env) end private def rvm(env) env.travis.rvm.last end def make_rbenv_version_command(env) %{ $(rbenv versions | sed -e 's/^\*/ /' | awk '{print $1}' | grep -v 'system' | grep '#{rvm env}' | tail -n1) }.compact end end end end end end