Sha256: 8d228b2e6440d792951fb659211280aced2018ade48554980b2ff905faf81292

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module Vx
  module Builder
    class Script

      Ruby = Struct.new(:app) do

        include Helper::TraceShCommand

        def call(env)
          if rvm env
            env.cache_key << "rvm-#{rvm env}"

            env.before_install.tap do |i|
              i << "source /etc/profile.d/rbenv.sh"
              i << 'eval "$(rbenv init -)" || true'
              i << "rbenv shell #{make_rbenv_version_command env}"
              i << trace_sh_command("export BUNDLE_GEMFILE=${PWD}/#{gemfile(env)}")
              i << trace_sh_command('export GEM_HOME=~/.rubygems')
            end

            env.announce.tap do |a|
              a << trace_sh_command("ruby --version")
              a << trace_sh_command("gem --version")
              a << trace_sh_command("bundle --version")
            end

            env.install.tap do |i|
              i << trace_sh_command("bundle install")
              i << trace_sh_command("bundle clean --force")
            end

            if env.source.cached_directories != false
              env.cached_directories.push "~/.rubygems"
            end
          end

          app.call(env)
        end

        private

          def rvm(env)
            env.source.rvm.first
          end

          def gemfile(env)
            env.source.gemfile.first || "Gemfile"
          end

          def make_rbenv_version_command(env)
            select_rbenv_version(env)
          end

          def select_rbenv_version(env)
            %{
              $(rbenv versions |
                sed -e 's/^\*/ /' |
                awk '{print $1}' |
                grep -v 'system' |
                grep '#{rvm env}' |
                tail -n1)
            }.gsub(/\n/, ' ').gsub(/ +/, ' ').strip
          end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vx-builder-0.0.16 lib/vx/builder/script/ruby.rb